<!DOCTYPE html>

<html>
  <head>
    <meta charset="utf-8">
    
    <title>Array API &mdash; NumPy v1.18 Manual</title>
    
    <link rel="stylesheet" type="text/css" href="../../_static/css/spc-bootstrap.css">
    <link rel="stylesheet" type="text/css" href="../../_static/css/spc-extend.css">
    <link rel="stylesheet" href="../../_static/scipy.css" type="text/css" >
    <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" >
    <link rel="stylesheet" href="../../_static/graphviz.css" type="text/css" >
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../../',
        VERSION:     '1.18.1',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  false
      };
    </script>
    <script type="text/javascript" src="../../_static/jquery.js"></script>
    <script type="text/javascript" src="../../_static/underscore.js"></script>
    <script type="text/javascript" src="../../_static/doctools.js"></script>
    <script type="text/javascript" src="../../_static/language_data.js"></script>
    <script type="text/javascript" src="../../_static/js/copybutton.js"></script>
    <link rel="author" title="About these documents" href="../../about.html" >
    <link rel="index" title="Index" href="../../genindex.html" >
    <link rel="search" title="Search" href="../../search.html" >
    <link rel="top" title="NumPy v1.18 Manual" href="../../index.html" >
    <link rel="up" title="NumPy C-API" href="index.html" >
    <link rel="next" title="Array Iterator API" href="iterator.html" >
    <link rel="prev" title="Data Type API" href="dtype.html" > 
  </head>
  <body>
<div class="container">
  <div class="top-scipy-org-logo-header" style="background-color: #a2bae8;">
    <a href="../../index.html">
      <img border=0 alt="NumPy" src="../../_static/numpy_logo.png"></a>
    </div>
  </div>
</div>


    <div class="container">
      <div class="main">
        
	<div class="row-fluid">
	  <div class="span12">
	    <div class="spc-navbar">
              
    <ul class="nav nav-pills pull-left">
        <li class="active"><a href="https://numpy.org/">NumPy.org</a></li>
        <li class="active"><a href="https://numpy.org/doc">Docs</a></li>
        
        <li class="active"><a href="../../index.html">NumPy v1.18 Manual</a></li>
        

          <li class="active"><a href="../index.html" >NumPy Reference</a></li>
          <li class="active"><a href="index.html" accesskey="U">NumPy C-API</a></li> 
    </ul>
              
              
    <ul class="nav nav-pills pull-right">
      <li class="active">
        <a href="../../genindex.html" title="General Index"
           accesskey="I">index</a>
      </li>
      <li class="active">
        <a href="iterator.html" title="Array Iterator API"
           accesskey="N">next</a>
      </li>
      <li class="active">
        <a href="dtype.html" title="Data Type API"
           accesskey="P">previous</a>
      </li>
    </ul>
              
	    </div>
	  </div>
	</div>
        

	<div class="row-fluid">
      <div class="spc-rightsidebar span3">
        <div class="sphinxsidebarwrapper">
  <h3><a href="../../contents.html">Table of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">Array API</a><ul>
<li><a class="reference internal" href="#array-structure-and-data-access">Array structure and data access</a><ul>
<li><a class="reference internal" href="#data-access">Data access</a></li>
</ul>
</li>
<li><a class="reference internal" href="#creating-arrays">Creating arrays</a><ul>
<li><a class="reference internal" href="#from-scratch">From scratch</a></li>
<li><a class="reference internal" href="#from-other-objects">From other objects</a></li>
</ul>
</li>
<li><a class="reference internal" href="#dealing-with-types">Dealing with types</a><ul>
<li><a class="reference internal" href="#general-check-of-python-type">General check of Python Type</a></li>
<li><a class="reference internal" href="#data-type-checking">Data-type checking</a></li>
<li><a class="reference internal" href="#converting-data-types">Converting data types</a></li>
<li><a class="reference internal" href="#new-data-types">New data types</a></li>
<li><a class="reference internal" href="#special-functions-for-npy-object">Special functions for NPY_OBJECT</a></li>
</ul>
</li>
<li><a class="reference internal" href="#array-flags">Array flags</a><ul>
<li><a class="reference internal" href="#basic-array-flags">Basic Array Flags</a></li>
<li><a class="reference internal" href="#combinations-of-array-flags">Combinations of array flags</a></li>
<li><a class="reference internal" href="#flag-like-constants">Flag-like constants</a></li>
<li><a class="reference internal" href="#flag-checking">Flag checking</a></li>
</ul>
</li>
<li><a class="reference internal" href="#array-method-alternative-api">Array method alternative API</a><ul>
<li><a class="reference internal" href="#conversion">Conversion</a></li>
<li><a class="reference internal" href="#shape-manipulation">Shape Manipulation</a></li>
<li><a class="reference internal" href="#item-selection-and-manipulation">Item selection and manipulation</a></li>
<li><a class="reference internal" href="#calculation">Calculation</a></li>
</ul>
</li>
<li><a class="reference internal" href="#functions">Functions</a><ul>
<li><a class="reference internal" href="#array-functions">Array Functions</a></li>
<li><a class="reference internal" href="#other-functions">Other functions</a></li>
</ul>
</li>
<li><a class="reference internal" href="#auxiliary-data-with-object-semantics">Auxiliary Data With Object Semantics</a></li>
<li><a class="reference internal" href="#array-iterators">Array Iterators</a></li>
<li><a class="reference internal" href="#broadcasting-multi-iterators">Broadcasting (multi-iterators)</a></li>
<li><a class="reference internal" href="#neighborhood-iterator">Neighborhood iterator</a></li>
<li><a class="reference internal" href="#array-scalars">Array Scalars</a></li>
<li><a class="reference internal" href="#data-type-descriptors">Data-type descriptors</a></li>
<li><a class="reference internal" href="#conversion-utilities">Conversion Utilities</a><ul>
<li><a class="reference internal" href="#for-use-with-pyarg-parsetuple">For use with <code class="xref c c-func docutils literal notranslate"><span class="pre">PyArg_ParseTuple</span></code></a></li>
<li><a class="reference internal" href="#other-conversions">Other conversions</a></li>
</ul>
</li>
<li><a class="reference internal" href="#miscellaneous">Miscellaneous</a><ul>
<li><a class="reference internal" href="#importing-the-api">Importing the API</a></li>
<li><a class="reference internal" href="#checking-the-api-version">Checking the API Version</a></li>
<li><a class="reference internal" href="#internal-flexibility">Internal Flexibility</a></li>
<li><a class="reference internal" href="#memory-management">Memory management</a></li>
<li><a class="reference internal" href="#threading-support">Threading support</a><ul>
<li><a class="reference internal" href="#group-1">Group 1</a></li>
<li><a class="reference internal" href="#group-2">Group 2</a></li>
</ul>
</li>
<li><a class="reference internal" href="#priority">Priority</a></li>
<li><a class="reference internal" href="#default-buffers">Default buffers</a></li>
<li><a class="reference internal" href="#other-constants">Other constants</a></li>
<li><a class="reference internal" href="#miscellaneous-macros">Miscellaneous Macros</a></li>
<li><a class="reference internal" href="#enumerated-types">Enumerated Types</a></li>
</ul>
</li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="dtype.html"
                        title="previous chapter">Data Type API</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="iterator.html"
                        title="next chapter">Array Iterator API</a></p>
<div id="searchbox" style="display: none" role="search">
  <h4>Quick search</h4>
    <div>
    <form class="search" action="../../search.html" method="get">
      <input type="text" style="width: inherit;" name="q" />
      <input type="submit" value="search" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    </div>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
          <div class="span9">
            
        <div class="bodywrapper">
          <div class="body" id="spc-section-body">
            
  <div class="section" id="array-api">
<h1>Array API<a class="headerlink" href="#array-api" title="Permalink to this headline">¶</a></h1>
<div class="line-block">
<div class="line">The test of a first-rate intelligence is the ability to hold two</div>
<div class="line">opposed ideas in the mind at the same time, and still retain the</div>
<div class="line">ability to function.</div>
<div class="line">— <em>F. Scott Fitzgerald</em></div>
</div>
<div class="line-block">
<div class="line">For a successful technology, reality must take precedence over public</div>
<div class="line">relations, for Nature cannot be fooled.</div>
<div class="line">— <em>Richard P. Feynman</em></div>
</div>
<div class="section" id="array-structure-and-data-access">
<span id="index-0"></span><h2>Array structure and data access<a class="headerlink" href="#array-structure-and-data-access" title="Permalink to this headline">¶</a></h2>
<p>These macros access the <a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyArrayObject</span></code></a> structure members and are
defined in <code class="docutils literal notranslate"><span class="pre">ndarraytypes.h</span></code>. The input argument, <em>arr</em>, can be any
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyObject</span> <span class="pre">*</span></code></a> that is directly interpretable as a
<a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyArrayObject</span> <span class="pre">*</span></code></a> (any instance of the <a class="reference internal" href="types-and-structures.html#c.PyArray_Type" title="PyArray_Type"><code class="xref c c-data docutils literal notranslate"><span class="pre">PyArray_Type</span></code></a>
and itssub-types).</p>
<dl class="function">
<dt id="c.PyArray_NDIM">
int <code class="sig-name descname">PyArray_NDIM</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a><em> *arr</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_NDIM" title="Permalink to this definition">¶</a></dt>
<dd><p>The number of dimensions in the array.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_FLAGS">
int <code class="sig-name descname">PyArray_FLAGS</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> arr</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_FLAGS" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns an integer representing the <a class="reference internal" href="#array-flags"><span class="std std-ref">array-flags</span></a>.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_TYPE">
int <code class="sig-name descname">PyArray_TYPE</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> arr</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_TYPE" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the (builtin) typenumber for the elements of this array.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_SETITEM">
int <code class="sig-name descname">PyArray_SETITEM</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> arr</em>, void*<em> itemptr</em>, <a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> obj</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_SETITEM" title="Permalink to this definition">¶</a></dt>
<dd><p>Convert obj and place it in the ndarray, <em>arr</em>, at the place
pointed to by itemptr. Return -1 if an error occurs or 0 on
success.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_ENABLEFLAGS">
void <code class="sig-name descname">PyArray_ENABLEFLAGS</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> arr</em>, int<em> flags</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_ENABLEFLAGS" title="Permalink to this definition">¶</a></dt>
<dd><div class="versionadded">
<p><span class="versionmodified added">New in version 1.7.</span></p>
</div>
<p>Enables the specified array flags. This function does no validation,
and assumes that you know what you’re doing.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_CLEARFLAGS">
void <code class="sig-name descname">PyArray_CLEARFLAGS</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> arr</em>, int<em> flags</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_CLEARFLAGS" title="Permalink to this definition">¶</a></dt>
<dd><div class="versionadded">
<p><span class="versionmodified added">New in version 1.7.</span></p>
</div>
<p>Clears the specified array flags. This function does no validation,
and assumes that you know what you’re doing.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_DATA">
void *<code class="sig-name descname">PyArray_DATA</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a><em> *arr</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_DATA" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="function">
<dt id="c.PyArray_BYTES">
char *<code class="sig-name descname">PyArray_BYTES</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a><em> *arr</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_BYTES" title="Permalink to this definition">¶</a></dt>
<dd><p>These two macros are similar and obtain the pointer to the
data-buffer for the array. The first macro can (and should be)
assigned to a particular pointer where the second is for generic
processing. If you have not guaranteed a contiguous and/or aligned
array then be sure you understand how to access the data in the
array to avoid memory and/or alignment problems.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_DIMS">
<a class="reference internal" href="dtype.html#c.npy_intp" title="npy_intp">npy_intp</a> *<code class="sig-name descname">PyArray_DIMS</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a><em> *arr</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_DIMS" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns a pointer to the dimensions/shape of the array. The
number of elements matches the number of dimensions
of the array. Can return <code class="docutils literal notranslate"><span class="pre">NULL</span></code> for 0-dimensional arrays.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_SHAPE">
<a class="reference internal" href="dtype.html#c.npy_intp" title="npy_intp">npy_intp</a> *<code class="sig-name descname">PyArray_SHAPE</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a><em> *arr</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_SHAPE" title="Permalink to this definition">¶</a></dt>
<dd><div class="versionadded">
<p><span class="versionmodified added">New in version 1.7.</span></p>
</div>
<p>A synonym for <a class="reference internal" href="#c.PyArray_DIMS" title="PyArray_DIMS"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_DIMS</span></code></a>, named to be consistent with the
<a class="reference internal" href="../generated/numpy.ndarray.shape.html#numpy.ndarray.shape" title="numpy.ndarray.shape"><code class="xref py py-obj docutils literal notranslate"><span class="pre">shape</span></code></a> usage within Python.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_STRIDES">
<a class="reference internal" href="dtype.html#c.npy_intp" title="npy_intp">npy_intp</a> *<code class="sig-name descname">PyArray_STRIDES</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> arr</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_STRIDES" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns a pointer to the strides of the array. The
number of elements matches the number of dimensions
of the array.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_DIM">
<a class="reference internal" href="dtype.html#c.npy_intp" title="npy_intp">npy_intp</a> <code class="sig-name descname">PyArray_DIM</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> arr</em>, int<em> n</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_DIM" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the shape in the <em>n</em> <img class="math" src="../../_images/math/93895e2e935384e36afcc41dd0bdfc48b06a0431.svg" alt="^{\textrm{th}}"/> dimension.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_STRIDE">
<a class="reference internal" href="dtype.html#c.npy_intp" title="npy_intp">npy_intp</a> <code class="sig-name descname">PyArray_STRIDE</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> arr</em>, int<em> n</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_STRIDE" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the stride in the <em>n</em> <img class="math" src="../../_images/math/93895e2e935384e36afcc41dd0bdfc48b06a0431.svg" alt="^{\textrm{th}}"/> dimension.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_ITEMSIZE">
<a class="reference internal" href="dtype.html#c.npy_intp" title="npy_intp">npy_intp</a> <code class="sig-name descname">PyArray_ITEMSIZE</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> arr</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_ITEMSIZE" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the itemsize for the elements of this array.</p>
<p>Note that, in the old API that was deprecated in version 1.7, this function
had the return type <code class="docutils literal notranslate"><span class="pre">int</span></code>.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_SIZE">
<a class="reference internal" href="dtype.html#c.npy_intp" title="npy_intp">npy_intp</a> <code class="sig-name descname">PyArray_SIZE</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> arr</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_SIZE" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the total size (in number of elements) of the array.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_Size">
<a class="reference internal" href="dtype.html#c.npy_intp" title="npy_intp">npy_intp</a> <code class="sig-name descname">PyArray_Size</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> obj</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_Size" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns 0 if <em>obj</em> is not a sub-class of ndarray. Otherwise,
returns the total number of elements in the array. Safer version
of <a class="reference internal" href="#c.PyArray_SIZE" title="PyArray_SIZE"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_SIZE</span></code></a> (<em>obj</em>).</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_NBYTES">
<a class="reference internal" href="dtype.html#c.npy_intp" title="npy_intp">npy_intp</a> <code class="sig-name descname">PyArray_NBYTES</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> arr</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_NBYTES" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the total number of bytes consumed by the array.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_BASE">
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a> *<code class="sig-name descname">PyArray_BASE</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> arr</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_BASE" title="Permalink to this definition">¶</a></dt>
<dd><p>This returns the base object of the array. In most cases, this
means the object which owns the memory the array is pointing at.</p>
<p>If you are constructing an array using the C API, and specifying
your own memory, you should use the function <a class="reference internal" href="#c.PyArray_SetBaseObject" title="PyArray_SetBaseObject"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_SetBaseObject</span></code></a>
to set the base to an object which owns the memory.</p>
<p>If the (deprecated) <a class="reference internal" href="#c.NPY_ARRAY_UPDATEIFCOPY" title="NPY_ARRAY_UPDATEIFCOPY"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_UPDATEIFCOPY</span></code></a> or the
<a class="reference internal" href="#c.NPY_ARRAY_WRITEBACKIFCOPY" title="NPY_ARRAY_WRITEBACKIFCOPY"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_WRITEBACKIFCOPY</span></code></a> flags are set, it has a different
meaning, namely base is the array into which the current array will
be copied upon copy resolution. This overloading of the base property
for two functions is likely to change in a future version of NumPy.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_DESCR">
<a class="reference internal" href="types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a> *<code class="sig-name descname">PyArray_DESCR</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> arr</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_DESCR" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns a borrowed reference to the dtype property of the array.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_DTYPE">
<a class="reference internal" href="types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a> *<code class="sig-name descname">PyArray_DTYPE</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> arr</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_DTYPE" title="Permalink to this definition">¶</a></dt>
<dd><div class="versionadded">
<p><span class="versionmodified added">New in version 1.7.</span></p>
</div>
<p>A synonym for PyArray_DESCR, named to be consistent with the
‘dtype’ usage within Python.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_GETITEM">
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a> *<code class="sig-name descname">PyArray_GETITEM</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> arr</em>, void*<em> itemptr</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_GETITEM" title="Permalink to this definition">¶</a></dt>
<dd><p>Get a Python object of a builtin type from the ndarray, <em>arr</em>,
at the location pointed to by itemptr. Return <code class="docutils literal notranslate"><span class="pre">NULL</span></code> on failure.</p>
<p><a class="reference internal" href="../generated/numpy.ndarray.item.html#numpy.ndarray.item" title="numpy.ndarray.item"><code class="xref py py-obj docutils literal notranslate"><span class="pre">numpy.ndarray.item</span></code></a> is identical to PyArray_GETITEM.</p>
</dd></dl>

<div class="section" id="data-access">
<h3>Data access<a class="headerlink" href="#data-access" title="Permalink to this headline">¶</a></h3>
<p>These functions and macros provide easy access to elements of the
ndarray from C. These work for all arrays. You may need to take care
when accessing the data in the array, however, if it is not in machine
byte-order, misaligned, or not writeable. In other words, be sure to
respect the state of the flags unless you know what you are doing, or
have previously guaranteed an array that is writeable, aligned, and in
machine byte-order using <a class="reference internal" href="#c.PyArray_FromAny" title="PyArray_FromAny"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_FromAny</span></code></a>. If you wish to handle all
types of arrays, the copyswap function for each type is useful for
handling misbehaved arrays. Some platforms (e.g. Solaris) do not like
misaligned data and will crash if you de-reference a misaligned
pointer. Other platforms (e.g. x86 Linux) will just work more slowly
with misaligned data.</p>
<dl class="function">
<dt id="c.PyArray_GetPtr">
void* <code class="sig-name descname">PyArray_GetPtr</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> aobj</em>, <a class="reference internal" href="dtype.html#c.npy_intp" title="npy_intp">npy_intp</a>*<em> ind</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_GetPtr" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a pointer to the data of the ndarray, <em>aobj</em>, at the
N-dimensional index given by the c-array, <em>ind</em>, (which must be
at least <em>aobj</em> -&gt;nd in size). You may want to typecast the
returned pointer to the data type of the ndarray.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_GETPTR1">
void* <code class="sig-name descname">PyArray_GETPTR1</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> obj</em>, <a class="reference internal" href="dtype.html#c.npy_intp" title="npy_intp">npy_intp</a><em> i</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_GETPTR1" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="function">
<dt id="c.PyArray_GETPTR2">
void* <code class="sig-name descname">PyArray_GETPTR2</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> obj</em>, <a class="reference internal" href="dtype.html#c.npy_intp" title="npy_intp">npy_intp</a><em> i</em>, <a class="reference internal" href="dtype.html#c.npy_intp" title="npy_intp">npy_intp</a><em> j</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_GETPTR2" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="function">
<dt id="c.PyArray_GETPTR3">
void* <code class="sig-name descname">PyArray_GETPTR3</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> obj</em>, <a class="reference internal" href="dtype.html#c.npy_intp" title="npy_intp">npy_intp</a><em> i</em>, <a class="reference internal" href="dtype.html#c.npy_intp" title="npy_intp">npy_intp</a><em> j</em>, <a class="reference internal" href="dtype.html#c.npy_intp" title="npy_intp">npy_intp</a><em> k</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_GETPTR3" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="function">
<dt id="c.PyArray_GETPTR4">
void* <code class="sig-name descname">PyArray_GETPTR4</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> obj</em>, <a class="reference internal" href="dtype.html#c.npy_intp" title="npy_intp">npy_intp</a><em> i</em>, <a class="reference internal" href="dtype.html#c.npy_intp" title="npy_intp">npy_intp</a><em> j</em>, <a class="reference internal" href="dtype.html#c.npy_intp" title="npy_intp">npy_intp</a><em> k</em>, <a class="reference internal" href="dtype.html#c.npy_intp" title="npy_intp">npy_intp</a><em> l</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_GETPTR4" title="Permalink to this definition">¶</a></dt>
<dd><p>Quick, inline access to the element at the given coordinates in
the ndarray, <em>obj</em>, which must have respectively 1, 2, 3, or 4
dimensions (this is not checked). The corresponding <em>i</em>, <em>j</em>,
<em>k</em>, and <em>l</em> coordinates can be any integer but will be
interpreted as <code class="docutils literal notranslate"><span class="pre">npy_intp</span></code>. You may want to typecast the
returned pointer to the data type of the ndarray.</p>
</dd></dl>

</div>
</div>
<div class="section" id="creating-arrays">
<h2>Creating arrays<a class="headerlink" href="#creating-arrays" title="Permalink to this headline">¶</a></h2>
<div class="section" id="from-scratch">
<h3>From scratch<a class="headerlink" href="#from-scratch" title="Permalink to this headline">¶</a></h3>
<dl class="function">
<dt id="c.PyArray_NewFromDescr">
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>* <code class="sig-name descname">PyArray_NewFromDescr</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/type.html#c.PyTypeObject" title="(in Python v3.9)">PyTypeObject</a>*<em> subtype</em>, <a class="reference internal" href="types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>*<em> descr</em>, int<em> nd</em>, <a class="reference internal" href="dtype.html#c.npy_intp" title="npy_intp">npy_intp</a> const*<em> dims</em>, <a class="reference internal" href="dtype.html#c.npy_intp" title="npy_intp">npy_intp</a> const*<em> strides</em>, void*<em> data</em>, int<em> flags</em>, <a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> obj</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_NewFromDescr" title="Permalink to this definition">¶</a></dt>
<dd><p>This function steals a reference to <em>descr</em>. The easiest way to get one
is using <a class="reference internal" href="#c.PyArray_DescrFromType" title="PyArray_DescrFromType"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_DescrFromType</span></code></a>.</p>
<p>This is the main array creation function. Most new arrays are
created with this flexible function.</p>
<p>The returned object is an object of Python-type <em>subtype</em>, which
must be a subtype of <a class="reference internal" href="types-and-structures.html#c.PyArray_Type" title="PyArray_Type"><code class="xref c c-data docutils literal notranslate"><span class="pre">PyArray_Type</span></code></a>.  The array has <em>nd</em>
dimensions, described by <em>dims</em>. The data-type descriptor of the
new array is <em>descr</em>.</p>
<p>If <em>subtype</em> is of an array subclass instead of the base
<a class="reference internal" href="types-and-structures.html#c.PyArray_Type" title="PyArray_Type"><code class="xref c c-data docutils literal notranslate"><span class="pre">&amp;PyArray_Type</span></code></a>, then <em>obj</em> is the object to pass to
the <a class="reference internal" href="../arrays.classes.html#numpy.class.__array_finalize__" title="numpy.class.__array_finalize__"><code class="xref py py-obj docutils literal notranslate"><span class="pre">__array_finalize__</span></code></a> method of the subclass.</p>
<p>If <em>data</em> is <code class="docutils literal notranslate"><span class="pre">NULL</span></code>, then new unitinialized memory will be allocated and
<em>flags</em> can be non-zero to indicate a Fortran-style contiguous array. Use
<a class="reference internal" href="#c.PyArray_FILLWBYTE" title="PyArray_FILLWBYTE"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_FILLWBYTE</span></code></a> to initialize the memory.</p>
<p>If <em>data</em> is not <code class="docutils literal notranslate"><span class="pre">NULL</span></code>, then it is assumed to point to the memory
to be used for the array and the <em>flags</em> argument is used as the
new flags for the array (except the state of <a class="reference internal" href="#c.NPY_ARRAY_OWNDATA" title="NPY_ARRAY_OWNDATA"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_OWNDATA</span></code></a>,
<a class="reference internal" href="#c.NPY_ARRAY_WRITEBACKIFCOPY" title="NPY_ARRAY_WRITEBACKIFCOPY"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_WRITEBACKIFCOPY</span></code></a> and <a class="reference internal" href="#c.NPY_ARRAY_UPDATEIFCOPY" title="NPY_ARRAY_UPDATEIFCOPY"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_UPDATEIFCOPY</span></code></a>
flags of the new array will be reset).</p>
<p>In addition, if <em>data</em> is non-NULL, then <em>strides</em> can
also be provided. If <em>strides</em> is <code class="docutils literal notranslate"><span class="pre">NULL</span></code>, then the array strides
are computed as C-style contiguous (default) or Fortran-style
contiguous (<em>flags</em> is nonzero for <em>data</em> = <code class="docutils literal notranslate"><span class="pre">NULL</span></code> or <em>flags</em> &amp;
<a class="reference internal" href="#c.NPY_ARRAY_F_CONTIGUOUS" title="NPY_ARRAY_F_CONTIGUOUS"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_F_CONTIGUOUS</span></code></a> is nonzero non-NULL <em>data</em>). Any
provided <em>dims</em> and <em>strides</em> are copied into newly allocated
dimension and strides arrays for the new array object.</p>
<p><a class="reference internal" href="#c.PyArray_CheckStrides" title="PyArray_CheckStrides"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_CheckStrides</span></code></a> can help verify non- <code class="docutils literal notranslate"><span class="pre">NULL</span></code> stride
information.</p>
<p>If <code class="docutils literal notranslate"><span class="pre">data</span></code> is provided, it must stay alive for the life of the array. One
way to manage this is through <a class="reference internal" href="#c.PyArray_SetBaseObject" title="PyArray_SetBaseObject"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_SetBaseObject</span></code></a></p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_NewLikeArray">
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>* <code class="sig-name descname">PyArray_NewLikeArray</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> prototype</em>, <a class="reference internal" href="#c.NPY_ORDER" title="NPY_ORDER">NPY_ORDER</a><em> order</em>, <a class="reference internal" href="types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>*<em> descr</em>, int<em> subok</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_NewLikeArray" title="Permalink to this definition">¶</a></dt>
<dd><div class="versionadded">
<p><span class="versionmodified added">New in version 1.6.</span></p>
</div>
<p>This function steals a reference to <em>descr</em> if it is not NULL.</p>
<p>This array creation routine allows for the convenient creation of
a new array matching an existing array’s shapes and memory layout,
possibly changing the layout and/or data type.</p>
<p>When <em>order</em> is <a class="reference internal" href="#c.NPY_ANYORDER" title="NPY_ANYORDER"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ANYORDER</span></code></a>, the result order is
<a class="reference internal" href="#c.NPY_FORTRANORDER" title="NPY_FORTRANORDER"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_FORTRANORDER</span></code></a> if <em>prototype</em> is a fortran array,
<a class="reference internal" href="#c.NPY_CORDER" title="NPY_CORDER"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_CORDER</span></code></a> otherwise.  When <em>order</em> is
<a class="reference internal" href="#c.NPY_KEEPORDER" title="NPY_KEEPORDER"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_KEEPORDER</span></code></a>, the result order matches that of <em>prototype</em>, even
when the axes of <em>prototype</em> aren’t in C or Fortran order.</p>
<p>If <em>descr</em> is NULL, the data type of <em>prototype</em> is used.</p>
<p>If <em>subok</em> is 1, the newly created array will use the sub-type of
<em>prototype</em> to create the new array, otherwise it will create a
base-class array.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_New">
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>* <code class="sig-name descname">PyArray_New</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/type.html#c.PyTypeObject" title="(in Python v3.9)">PyTypeObject</a>*<em> subtype</em>, int<em> nd</em>, <a class="reference internal" href="dtype.html#c.npy_intp" title="npy_intp">npy_intp</a> const*<em> dims</em>, int<em> type_num</em>, <a class="reference internal" href="dtype.html#c.npy_intp" title="npy_intp">npy_intp</a> const*<em> strides</em>, void*<em> data</em>, int<em> itemsize</em>, int<em> flags</em>, <a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> obj</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_New" title="Permalink to this definition">¶</a></dt>
<dd><p>This is similar to <a class="reference internal" href="#c.PyArray_NewFromDescr" title="PyArray_NewFromDescr"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_NewFromDescr</span></code></a> (…) except you
specify the data-type descriptor with <em>type_num</em> and <em>itemsize</em>,
where <em>type_num</em> corresponds to a builtin (or user-defined)
type. If the type always has the same number of bytes, then
itemsize is ignored. Otherwise, itemsize specifies the particular
size of this array.</p>
</dd></dl>

<div class="admonition warning">
<p class="admonition-title">Warning</p>
<p>If data is passed to <a class="reference internal" href="#c.PyArray_NewFromDescr" title="PyArray_NewFromDescr"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_NewFromDescr</span></code></a> or <a class="reference internal" href="#c.PyArray_New" title="PyArray_New"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_New</span></code></a>,
this memory must not be deallocated until the new array is
deleted.  If this data came from another Python object, this can
be accomplished using <a class="reference external" href="https://docs.python.org/dev/c-api/refcounting.html#c.Py_INCREF" title="(in Python v3.9)"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_INCREF</span></code></a> on that object and setting the
base member of the new array to point to that object. If strides
are passed in they must be consistent with the dimensions, the
itemsize, and the data of the array.</p>
</div>
<dl class="function">
<dt id="c.PyArray_SimpleNew">
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>* <code class="sig-name descname">PyArray_SimpleNew</code><span class="sig-paren">(</span>int<em> nd</em>, <a class="reference internal" href="dtype.html#c.npy_intp" title="npy_intp">npy_intp</a> const*<em> dims</em>, int<em> typenum</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_SimpleNew" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a new uninitialized array of type, <em>typenum</em>, whose size in
each of <em>nd</em> dimensions is given by the integer array, <em>dims</em>.The memory
for the array is uninitialized (unless typenum is <a class="reference internal" href="dtype.html#c.NPY_OBJECT" title="NPY_OBJECT"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_OBJECT</span></code></a>
in which case each element in the array is set to NULL). The
<em>typenum</em> argument allows specification of any of the builtin
data-types such as <a class="reference internal" href="dtype.html#c.NPY_FLOAT" title="NPY_FLOAT"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_FLOAT</span></code></a> or <a class="reference internal" href="dtype.html#c.NPY_LONG" title="NPY_LONG"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_LONG</span></code></a>. The
memory for the array can be set to zero if desired using
<a class="reference internal" href="#c.PyArray_FILLWBYTE" title="PyArray_FILLWBYTE"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_FILLWBYTE</span></code></a> (return_object, 0).This function cannot be
used to create a flexible-type array (no itemsize given).</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_SimpleNewFromData">
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>* <code class="sig-name descname">PyArray_SimpleNewFromData</code><span class="sig-paren">(</span>int<em> nd</em>, <a class="reference internal" href="dtype.html#c.npy_intp" title="npy_intp">npy_intp</a> const*<em> dims</em>, int<em> typenum</em>, void*<em> data</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_SimpleNewFromData" title="Permalink to this definition">¶</a></dt>
<dd><p>Create an array wrapper around <em>data</em> pointed to by the given
pointer. The array flags will have a default that the data area is
well-behaved and C-style contiguous. The shape of the array is
given by the <em>dims</em> c-array of length <em>nd</em>. The data-type of the
array is indicated by <em>typenum</em>. If data comes from another
reference-counted Python object, the reference count on this object
should be increased after the pointer is passed in, and the base member
of the returned ndarray should point to the Python object that owns
the data. This will ensure that the provided memory is not
freed while the returned array is in existence. To free memory as soon
as the ndarray is deallocated, set the OWNDATA flag on the returned ndarray.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_SimpleNewFromDescr">
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>* <code class="sig-name descname">PyArray_SimpleNewFromDescr</code><span class="sig-paren">(</span>int<em> nd</em>, <a class="reference internal" href="dtype.html#c.npy_int" title="npy_int">npy_int</a> const*<em> dims</em>, <a class="reference internal" href="types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>*<em> descr</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_SimpleNewFromDescr" title="Permalink to this definition">¶</a></dt>
<dd><p>This function steals a reference to <em>descr</em>.</p>
<p>Create a new array with the provided data-type descriptor, <em>descr</em>,
of the shape determined by <em>nd</em> and <em>dims</em>.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_FILLWBYTE">
<code class="sig-name descname">PyArray_FILLWBYTE</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> obj</em>, int<em> val</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_FILLWBYTE" title="Permalink to this definition">¶</a></dt>
<dd><p>Fill the array pointed to by <em>obj</em> —which must be a (subclass
of) ndarray—with the contents of <em>val</em> (evaluated as a byte).
This macro calls memset, so obj must be contiguous.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_Zeros">
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>* <code class="sig-name descname">PyArray_Zeros</code><span class="sig-paren">(</span>int<em> nd</em>, <a class="reference internal" href="dtype.html#c.npy_intp" title="npy_intp">npy_intp</a> const*<em> dims</em>, <a class="reference internal" href="types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>*<em> dtype</em>, int<em> fortran</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_Zeros" title="Permalink to this definition">¶</a></dt>
<dd><p>Construct a new <em>nd</em> -dimensional array with shape given by <em>dims</em>
and data type given by <em>dtype</em>. If <em>fortran</em> is non-zero, then a
Fortran-order array is created, otherwise a C-order array is
created. Fill the memory with zeros (or the 0 object if <em>dtype</em>
corresponds to <a class="reference internal" href="dtype.html#c.NPY_OBJECT" title="NPY_OBJECT"><code class="xref c c-type docutils literal notranslate"><span class="pre">NPY_OBJECT</span></code></a> ).</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_ZEROS">
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>* <code class="sig-name descname">PyArray_ZEROS</code><span class="sig-paren">(</span>int<em> nd</em>, <a class="reference internal" href="dtype.html#c.npy_intp" title="npy_intp">npy_intp</a> const*<em> dims</em>, int<em> type_num</em>, int<em> fortran</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_ZEROS" title="Permalink to this definition">¶</a></dt>
<dd><p>Macro form of <a class="reference internal" href="#c.PyArray_Zeros" title="PyArray_Zeros"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_Zeros</span></code></a> which takes a type-number instead
of a data-type object.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_Empty">
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>* <code class="sig-name descname">PyArray_Empty</code><span class="sig-paren">(</span>int<em> nd</em>, <a class="reference internal" href="dtype.html#c.npy_intp" title="npy_intp">npy_intp</a> const*<em> dims</em>, <a class="reference internal" href="types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>*<em> dtype</em>, int<em> fortran</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_Empty" title="Permalink to this definition">¶</a></dt>
<dd><p>Construct a new <em>nd</em> -dimensional array with shape given by <em>dims</em>
and data type given by <em>dtype</em>. If <em>fortran</em> is non-zero, then a
Fortran-order array is created, otherwise a C-order array is
created. The array is uninitialized unless the data type
corresponds to <a class="reference internal" href="dtype.html#c.NPY_OBJECT" title="NPY_OBJECT"><code class="xref c c-type docutils literal notranslate"><span class="pre">NPY_OBJECT</span></code></a> in which case the array is
filled with <a class="reference external" href="https://docs.python.org/dev/c-api/none.html#c.Py_None" title="(in Python v3.9)"><code class="xref c c-data docutils literal notranslate"><span class="pre">Py_None</span></code></a>.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_EMPTY">
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>* <code class="sig-name descname">PyArray_EMPTY</code><span class="sig-paren">(</span>int<em> nd</em>, <a class="reference internal" href="dtype.html#c.npy_intp" title="npy_intp">npy_intp</a> const*<em> dims</em>, int<em> typenum</em>, int<em> fortran</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_EMPTY" title="Permalink to this definition">¶</a></dt>
<dd><p>Macro form of <a class="reference internal" href="#c.PyArray_Empty" title="PyArray_Empty"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_Empty</span></code></a> which takes a type-number,
<em>typenum</em>, instead of a data-type object.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_Arange">
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>* <code class="sig-name descname">PyArray_Arange</code><span class="sig-paren">(</span>double<em> start</em>, double<em> stop</em>, double<em> step</em>, int<em> typenum</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_Arange" title="Permalink to this definition">¶</a></dt>
<dd><p>Construct a new 1-dimensional array of data-type, <em>typenum</em>, that
ranges from <em>start</em> to <em>stop</em> (exclusive) in increments of <em>step</em>
. Equivalent to <strong>arange</strong> (<em>start</em>, <em>stop</em>, <em>step</em>, dtype).</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_ArangeObj">
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>* <code class="sig-name descname">PyArray_ArangeObj</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> start</em>, <a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> stop</em>, <a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> step</em>, <a class="reference internal" href="types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>*<em> descr</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_ArangeObj" title="Permalink to this definition">¶</a></dt>
<dd><p>Construct a new 1-dimensional array of data-type determined by
<code class="docutils literal notranslate"><span class="pre">descr</span></code>, that ranges from <code class="docutils literal notranslate"><span class="pre">start</span></code> to <code class="docutils literal notranslate"><span class="pre">stop</span></code> (exclusive) in
increments of <code class="docutils literal notranslate"><span class="pre">step</span></code>. Equivalent to arange( <code class="docutils literal notranslate"><span class="pre">start</span></code>,
<code class="docutils literal notranslate"><span class="pre">stop</span></code>, <code class="docutils literal notranslate"><span class="pre">step</span></code>, <code class="docutils literal notranslate"><span class="pre">typenum</span></code> ).</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_SetBaseObject">
int <code class="sig-name descname">PyArray_SetBaseObject</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> arr</em>, <a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> obj</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_SetBaseObject" title="Permalink to this definition">¶</a></dt>
<dd><div class="versionadded">
<p><span class="versionmodified added">New in version 1.7.</span></p>
</div>
<p>This function <strong>steals a reference</strong> to <code class="docutils literal notranslate"><span class="pre">obj</span></code> and sets it as the
base property of <code class="docutils literal notranslate"><span class="pre">arr</span></code>.</p>
<p>If you construct an array by passing in your own memory buffer as
a parameter, you need to set the array’s <em class="xref py py-obj">base</em> property to ensure
the lifetime of the memory buffer is appropriate.</p>
<p>The return value is 0 on success, -1 on failure.</p>
<p>If the object provided is an array, this function traverses the
chain of <em class="xref py py-obj">base</em> pointers so that each array points to the owner
of the memory directly. Once the base is set, it may not be changed
to another value.</p>
</dd></dl>

</div>
<div class="section" id="from-other-objects">
<h3>From other objects<a class="headerlink" href="#from-other-objects" title="Permalink to this headline">¶</a></h3>
<dl class="function">
<dt id="c.PyArray_FromAny">
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>* <code class="sig-name descname">PyArray_FromAny</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> op</em>, <a class="reference internal" href="types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>*<em> dtype</em>, int<em> min_depth</em>, int<em> max_depth</em>, int<em> requirements</em>, <a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> context</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_FromAny" title="Permalink to this definition">¶</a></dt>
<dd><p>This is the main function used to obtain an array from any nested
sequence, or object that exposes the array interface, <em>op</em>. The
parameters allow specification of the required <em>dtype</em>, the
minimum (<em>min_depth</em>) and maximum (<em>max_depth</em>) number of
dimensions acceptable, and other <em>requirements</em> for the array. This
function <strong>steals a reference</strong> to the dtype argument, which needs
to be a <a class="reference internal" href="types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyArray_Descr</span></code></a> structure
indicating the desired data-type (including required
byteorder). The <em>dtype</em> argument may be <code class="docutils literal notranslate"><span class="pre">NULL</span></code>, indicating that any
data-type (and byteorder) is acceptable. Unless
<a class="reference internal" href="#c.NPY_ARRAY_FORCECAST" title="NPY_ARRAY_FORCECAST"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_FORCECAST</span></code></a> is present in <code class="docutils literal notranslate"><span class="pre">flags</span></code>,
this call will generate an error if the data
type cannot be safely obtained from the object. If you want to use
<code class="docutils literal notranslate"><span class="pre">NULL</span></code> for the <em>dtype</em> and ensure the array is notswapped then
use <a class="reference internal" href="#c.PyArray_CheckFromAny" title="PyArray_CheckFromAny"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_CheckFromAny</span></code></a>. A value of 0 for either of the
depth parameters causes the parameter to be ignored. Any of the
following array flags can be added (<em>e.g.</em> using |) to get the
<em>requirements</em> argument. If your code can handle general (<em>e.g.</em>
strided, byte-swapped, or unaligned arrays) then <em>requirements</em>
may be 0. Also, if <em>op</em> is not already an array (or does not
expose the array interface), then a new array will be created (and
filled from <em>op</em> using the sequence protocol). The new array will
have <a class="reference internal" href="#c.NPY_ARRAY_DEFAULT" title="NPY_ARRAY_DEFAULT"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_DEFAULT</span></code></a> as its flags member. The <em>context</em> argument
is passed to the <a class="reference internal" href="../arrays.classes.html#numpy.class.__array__" title="numpy.class.__array__"><code class="xref py py-obj docutils literal notranslate"><span class="pre">__array__</span></code></a> method of <em>op</em> and is only used if
the array is constructed that way. Almost always this
parameter is <code class="docutils literal notranslate"><span class="pre">NULL</span></code>.</p>
<dl class="var">
<dt id="c.NPY_ARRAY_C_CONTIGUOUS">
<code class="sig-name descname">NPY_ARRAY_C_CONTIGUOUS</code><a class="headerlink" href="#c.NPY_ARRAY_C_CONTIGUOUS" title="Permalink to this definition">¶</a></dt>
<dd><p>Make sure the returned array is C-style contiguous</p>
</dd></dl>

<dl class="var">
<dt id="c.NPY_ARRAY_F_CONTIGUOUS">
<code class="sig-name descname">NPY_ARRAY_F_CONTIGUOUS</code><a class="headerlink" href="#c.NPY_ARRAY_F_CONTIGUOUS" title="Permalink to this definition">¶</a></dt>
<dd><p>Make sure the returned array is Fortran-style contiguous.</p>
</dd></dl>

<dl class="var">
<dt id="c.NPY_ARRAY_ALIGNED">
<code class="sig-name descname">NPY_ARRAY_ALIGNED</code><a class="headerlink" href="#c.NPY_ARRAY_ALIGNED" title="Permalink to this definition">¶</a></dt>
<dd><p>Make sure the returned array is aligned on proper boundaries for its
data type. An aligned array has the data pointer and every strides
factor as a multiple of the alignment factor for the data-type-
descriptor.</p>
</dd></dl>

<dl class="var">
<dt id="c.NPY_ARRAY_WRITEABLE">
<code class="sig-name descname">NPY_ARRAY_WRITEABLE</code><a class="headerlink" href="#c.NPY_ARRAY_WRITEABLE" title="Permalink to this definition">¶</a></dt>
<dd><p>Make sure the returned array can be written to.</p>
</dd></dl>

<dl class="var">
<dt id="c.NPY_ARRAY_ENSURECOPY">
<code class="sig-name descname">NPY_ARRAY_ENSURECOPY</code><a class="headerlink" href="#c.NPY_ARRAY_ENSURECOPY" title="Permalink to this definition">¶</a></dt>
<dd><p>Make sure a copy is made of <em>op</em>. If this flag is not
present, data is not copied if it can be avoided.</p>
</dd></dl>

<dl class="var">
<dt id="c.NPY_ARRAY_ENSUREARRAY">
<code class="sig-name descname">NPY_ARRAY_ENSUREARRAY</code><a class="headerlink" href="#c.NPY_ARRAY_ENSUREARRAY" title="Permalink to this definition">¶</a></dt>
<dd><p>Make sure the result is a base-class ndarray. By
default, if <em>op</em> is an instance of a subclass of
ndarray, an instance of that same subclass is returned. If
this flag is set, an ndarray object will be returned instead.</p>
</dd></dl>

<dl class="var">
<dt id="c.NPY_ARRAY_FORCECAST">
<code class="sig-name descname">NPY_ARRAY_FORCECAST</code><a class="headerlink" href="#c.NPY_ARRAY_FORCECAST" title="Permalink to this definition">¶</a></dt>
<dd><p>Force a cast to the output type even if it cannot be done
safely.  Without this flag, a data cast will occur only if it
can be done safely, otherwise an error is raised.</p>
</dd></dl>

<dl class="var">
<dt id="c.NPY_ARRAY_WRITEBACKIFCOPY">
<code class="sig-name descname">NPY_ARRAY_WRITEBACKIFCOPY</code><a class="headerlink" href="#c.NPY_ARRAY_WRITEBACKIFCOPY" title="Permalink to this definition">¶</a></dt>
<dd><p>If <em>op</em> is already an array, but does not satisfy the
requirements, then a copy is made (which will satisfy the
requirements). If this flag is present and a copy (of an object
that is already an array) must be made, then the corresponding
<a class="reference internal" href="#c.NPY_ARRAY_WRITEBACKIFCOPY" title="NPY_ARRAY_WRITEBACKIFCOPY"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_WRITEBACKIFCOPY</span></code></a> flag is set in the returned
copy and <em>op</em> is made to be read-only. You must be sure to call
<a class="reference internal" href="#c.PyArray_ResolveWritebackIfCopy" title="PyArray_ResolveWritebackIfCopy"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_ResolveWritebackIfCopy</span></code></a> to copy the contents
back into <em>op</em> and the <em>op</em> array
will be made writeable again. If <em>op</em> is not writeable to begin
with, or if it is not already an array, then an error is raised.</p>
</dd></dl>

<dl class="var">
<dt id="c.NPY_ARRAY_UPDATEIFCOPY">
<code class="sig-name descname">NPY_ARRAY_UPDATEIFCOPY</code><a class="headerlink" href="#c.NPY_ARRAY_UPDATEIFCOPY" title="Permalink to this definition">¶</a></dt>
<dd><p>Deprecated. Use <a class="reference internal" href="#c.NPY_ARRAY_WRITEBACKIFCOPY" title="NPY_ARRAY_WRITEBACKIFCOPY"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_WRITEBACKIFCOPY</span></code></a>, which is similar.
This flag “automatically” copies the data back when the returned
array is deallocated, which is not supported in all python
implementations.</p>
</dd></dl>

<dl class="var">
<dt id="c.NPY_ARRAY_BEHAVED">
<code class="sig-name descname">NPY_ARRAY_BEHAVED</code><a class="headerlink" href="#c.NPY_ARRAY_BEHAVED" title="Permalink to this definition">¶</a></dt>
<dd><p><a class="reference internal" href="#c.NPY_ARRAY_ALIGNED" title="NPY_ARRAY_ALIGNED"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_ALIGNED</span></code></a> | <a class="reference internal" href="#c.NPY_ARRAY_WRITEABLE" title="NPY_ARRAY_WRITEABLE"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_WRITEABLE</span></code></a></p>
</dd></dl>

<dl class="var">
<dt id="c.NPY_ARRAY_CARRAY">
<code class="sig-name descname">NPY_ARRAY_CARRAY</code><a class="headerlink" href="#c.NPY_ARRAY_CARRAY" title="Permalink to this definition">¶</a></dt>
<dd><p><a class="reference internal" href="#c.NPY_ARRAY_C_CONTIGUOUS" title="NPY_ARRAY_C_CONTIGUOUS"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_C_CONTIGUOUS</span></code></a> | <a class="reference internal" href="#c.NPY_ARRAY_BEHAVED" title="NPY_ARRAY_BEHAVED"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_BEHAVED</span></code></a></p>
</dd></dl>

<dl class="var">
<dt id="c.NPY_ARRAY_CARRAY_RO">
<code class="sig-name descname">NPY_ARRAY_CARRAY_RO</code><a class="headerlink" href="#c.NPY_ARRAY_CARRAY_RO" title="Permalink to this definition">¶</a></dt>
<dd><p><a class="reference internal" href="#c.NPY_ARRAY_C_CONTIGUOUS" title="NPY_ARRAY_C_CONTIGUOUS"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_C_CONTIGUOUS</span></code></a> | <a class="reference internal" href="#c.NPY_ARRAY_ALIGNED" title="NPY_ARRAY_ALIGNED"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_ALIGNED</span></code></a></p>
</dd></dl>

<dl class="var">
<dt id="c.NPY_ARRAY_FARRAY">
<code class="sig-name descname">NPY_ARRAY_FARRAY</code><a class="headerlink" href="#c.NPY_ARRAY_FARRAY" title="Permalink to this definition">¶</a></dt>
<dd><p><a class="reference internal" href="#c.NPY_ARRAY_F_CONTIGUOUS" title="NPY_ARRAY_F_CONTIGUOUS"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_F_CONTIGUOUS</span></code></a> | <a class="reference internal" href="#c.NPY_ARRAY_BEHAVED" title="NPY_ARRAY_BEHAVED"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_BEHAVED</span></code></a></p>
</dd></dl>

<dl class="var">
<dt id="c.NPY_ARRAY_FARRAY_RO">
<code class="sig-name descname">NPY_ARRAY_FARRAY_RO</code><a class="headerlink" href="#c.NPY_ARRAY_FARRAY_RO" title="Permalink to this definition">¶</a></dt>
<dd><p><a class="reference internal" href="#c.NPY_ARRAY_F_CONTIGUOUS" title="NPY_ARRAY_F_CONTIGUOUS"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_F_CONTIGUOUS</span></code></a> | <a class="reference internal" href="#c.NPY_ARRAY_ALIGNED" title="NPY_ARRAY_ALIGNED"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_ALIGNED</span></code></a></p>
</dd></dl>

<dl class="var">
<dt id="c.NPY_ARRAY_DEFAULT">
<code class="sig-name descname">NPY_ARRAY_DEFAULT</code><a class="headerlink" href="#c.NPY_ARRAY_DEFAULT" title="Permalink to this definition">¶</a></dt>
<dd><p><a class="reference internal" href="#c.NPY_ARRAY_CARRAY" title="NPY_ARRAY_CARRAY"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_CARRAY</span></code></a></p>
</dd></dl>

<dl class="var">
<dt id="c.NPY_ARRAY_IN_ARRAY">
<code class="sig-name descname">NPY_ARRAY_IN_ARRAY</code><a class="headerlink" href="#c.NPY_ARRAY_IN_ARRAY" title="Permalink to this definition">¶</a></dt>
<dd><p><a class="reference internal" href="#c.NPY_ARRAY_C_CONTIGUOUS" title="NPY_ARRAY_C_CONTIGUOUS"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_C_CONTIGUOUS</span></code></a> | <a class="reference internal" href="#c.NPY_ARRAY_ALIGNED" title="NPY_ARRAY_ALIGNED"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_ALIGNED</span></code></a></p>
</dd></dl>

<dl class="var">
<dt id="c.NPY_ARRAY_IN_FARRAY">
<code class="sig-name descname">NPY_ARRAY_IN_FARRAY</code><a class="headerlink" href="#c.NPY_ARRAY_IN_FARRAY" title="Permalink to this definition">¶</a></dt>
<dd><p><a class="reference internal" href="#c.NPY_ARRAY_F_CONTIGUOUS" title="NPY_ARRAY_F_CONTIGUOUS"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_F_CONTIGUOUS</span></code></a> | <a class="reference internal" href="#c.NPY_ARRAY_ALIGNED" title="NPY_ARRAY_ALIGNED"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_ALIGNED</span></code></a></p>
</dd></dl>

<dl class="var">
<dt id="c.NPY_OUT_ARRAY">
<code class="sig-name descname">NPY_OUT_ARRAY</code><a class="headerlink" href="#c.NPY_OUT_ARRAY" title="Permalink to this definition">¶</a></dt>
<dd><p><a class="reference internal" href="#c.NPY_ARRAY_C_CONTIGUOUS" title="NPY_ARRAY_C_CONTIGUOUS"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_C_CONTIGUOUS</span></code></a> | <a class="reference internal" href="#c.NPY_ARRAY_WRITEABLE" title="NPY_ARRAY_WRITEABLE"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_WRITEABLE</span></code></a> |
<a class="reference internal" href="#c.NPY_ARRAY_ALIGNED" title="NPY_ARRAY_ALIGNED"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_ALIGNED</span></code></a></p>
</dd></dl>

<dl class="var">
<dt id="c.NPY_ARRAY_OUT_ARRAY">
<code class="sig-name descname">NPY_ARRAY_OUT_ARRAY</code><a class="headerlink" href="#c.NPY_ARRAY_OUT_ARRAY" title="Permalink to this definition">¶</a></dt>
<dd><p><a class="reference internal" href="#c.NPY_ARRAY_C_CONTIGUOUS" title="NPY_ARRAY_C_CONTIGUOUS"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_C_CONTIGUOUS</span></code></a> | <a class="reference internal" href="#c.NPY_ARRAY_ALIGNED" title="NPY_ARRAY_ALIGNED"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_ALIGNED</span></code></a> |
<a class="reference internal" href="#c.NPY_ARRAY_WRITEABLE" title="NPY_ARRAY_WRITEABLE"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_WRITEABLE</span></code></a></p>
</dd></dl>

<dl class="var">
<dt id="c.NPY_ARRAY_OUT_FARRAY">
<code class="sig-name descname">NPY_ARRAY_OUT_FARRAY</code><a class="headerlink" href="#c.NPY_ARRAY_OUT_FARRAY" title="Permalink to this definition">¶</a></dt>
<dd><p><a class="reference internal" href="#c.NPY_ARRAY_F_CONTIGUOUS" title="NPY_ARRAY_F_CONTIGUOUS"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_F_CONTIGUOUS</span></code></a> | <a class="reference internal" href="#c.NPY_ARRAY_WRITEABLE" title="NPY_ARRAY_WRITEABLE"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_WRITEABLE</span></code></a> |
<a class="reference internal" href="#c.NPY_ARRAY_ALIGNED" title="NPY_ARRAY_ALIGNED"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_ALIGNED</span></code></a></p>
</dd></dl>

<dl class="var">
<dt id="c.NPY_ARRAY_INOUT_ARRAY">
<code class="sig-name descname">NPY_ARRAY_INOUT_ARRAY</code><a class="headerlink" href="#c.NPY_ARRAY_INOUT_ARRAY" title="Permalink to this definition">¶</a></dt>
<dd><p><a class="reference internal" href="#c.NPY_ARRAY_C_CONTIGUOUS" title="NPY_ARRAY_C_CONTIGUOUS"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_C_CONTIGUOUS</span></code></a> | <a class="reference internal" href="#c.NPY_ARRAY_WRITEABLE" title="NPY_ARRAY_WRITEABLE"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_WRITEABLE</span></code></a> |
<a class="reference internal" href="#c.NPY_ARRAY_ALIGNED" title="NPY_ARRAY_ALIGNED"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_ALIGNED</span></code></a> | <a class="reference internal" href="#c.NPY_ARRAY_WRITEBACKIFCOPY" title="NPY_ARRAY_WRITEBACKIFCOPY"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_WRITEBACKIFCOPY</span></code></a> |
<a class="reference internal" href="#c.NPY_ARRAY_UPDATEIFCOPY" title="NPY_ARRAY_UPDATEIFCOPY"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_UPDATEIFCOPY</span></code></a></p>
</dd></dl>

<dl class="var">
<dt id="c.NPY_ARRAY_INOUT_FARRAY">
<code class="sig-name descname">NPY_ARRAY_INOUT_FARRAY</code><a class="headerlink" href="#c.NPY_ARRAY_INOUT_FARRAY" title="Permalink to this definition">¶</a></dt>
<dd><p><a class="reference internal" href="#c.NPY_ARRAY_F_CONTIGUOUS" title="NPY_ARRAY_F_CONTIGUOUS"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_F_CONTIGUOUS</span></code></a> | <a class="reference internal" href="#c.NPY_ARRAY_WRITEABLE" title="NPY_ARRAY_WRITEABLE"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_WRITEABLE</span></code></a> |
<a class="reference internal" href="#c.NPY_ARRAY_ALIGNED" title="NPY_ARRAY_ALIGNED"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_ALIGNED</span></code></a> | <a class="reference internal" href="#c.NPY_ARRAY_WRITEBACKIFCOPY" title="NPY_ARRAY_WRITEBACKIFCOPY"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_WRITEBACKIFCOPY</span></code></a> |
<a class="reference internal" href="#c.NPY_ARRAY_UPDATEIFCOPY" title="NPY_ARRAY_UPDATEIFCOPY"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_UPDATEIFCOPY</span></code></a></p>
</dd></dl>

</dd></dl>

<dl class="function">
<dt id="c.PyArray_GetArrayParamsFromObject">
int <code class="sig-name descname">PyArray_GetArrayParamsFromObject</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> op</em>, <a class="reference internal" href="types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>*<em> requested_dtype</em>, <a class="reference internal" href="dtype.html#c.npy_bool" title="npy_bool">npy_bool</a><em> writeable</em>, <a class="reference internal" href="types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>**<em> out_dtype</em>, int*<em> out_ndim</em>, <a class="reference internal" href="dtype.html#c.npy_intp" title="npy_intp">npy_intp</a>*<em> out_dims</em>, <a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>**<em> out_arr</em>, <a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> context</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_GetArrayParamsFromObject" title="Permalink to this definition">¶</a></dt>
<dd><div class="versionadded">
<p><span class="versionmodified added">New in version 1.6.</span></p>
</div>
<p>Retrieves the array parameters for viewing/converting an arbitrary
PyObject* to a NumPy array. This allows the “innate type and shape”
of Python list-of-lists to be discovered without
actually converting to an array. PyArray_FromAny calls this function
to analyze its input.</p>
<p>In some cases, such as structured arrays and the <a class="reference internal" href="../arrays.classes.html#numpy.class.__array__" title="numpy.class.__array__"><code class="xref py py-obj docutils literal notranslate"><span class="pre">__array__</span></code></a> interface,
a data type needs to be used to make sense of the object.  When
this is needed, provide a Descr for ‘requested_dtype’, otherwise
provide NULL. This reference is not stolen. Also, if the requested
dtype doesn’t modify the interpretation of the input, out_dtype will
still get the “innate” dtype of the object, not the dtype passed
in ‘requested_dtype’.</p>
<p>If writing to the value in ‘op’ is desired, set the boolean
‘writeable’ to 1.  This raises an error when ‘op’ is a scalar, list
of lists, or other non-writeable ‘op’. This differs from passing
<a class="reference internal" href="#c.NPY_ARRAY_WRITEABLE" title="NPY_ARRAY_WRITEABLE"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_WRITEABLE</span></code></a> to PyArray_FromAny, where the writeable array may
be a copy of the input.</p>
<p>When success (0 return value) is returned, either out_arr
is filled with a non-NULL PyArrayObject and
the rest of the parameters are untouched, or out_arr is
filled with NULL, and the rest of the parameters are filled.</p>
<p>Typical usage:</p>
<div class="highlight-c notranslate"><div class="highlight"><pre><span></span><span class="n">PyArrayObject</span> <span class="o">*</span><span class="n">arr</span> <span class="o">=</span> <span class="nb">NULL</span><span class="p">;</span>
<span class="n">PyArray_Descr</span> <span class="o">*</span><span class="n">dtype</span> <span class="o">=</span> <span class="nb">NULL</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">ndim</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
<span class="n">npy_intp</span> <span class="n">dims</span><span class="p">[</span><span class="n">NPY_MAXDIMS</span><span class="p">];</span>

<span class="k">if</span> <span class="p">(</span><span class="n">PyArray_GetArrayParamsFromObject</span><span class="p">(</span><span class="n">op</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">dtype</span><span class="p">,</span>
                                    <span class="o">&amp;</span><span class="n">ndim</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">dims</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">arr</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">)</span> <span class="o">&lt;</span> <span class="mi">0</span><span class="p">)</span> <span class="p">{</span>
    <span class="k">return</span> <span class="nb">NULL</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="n">arr</span> <span class="o">==</span> <span class="nb">NULL</span><span class="p">)</span> <span class="p">{</span>
    <span class="cm">/*</span>
<span class="cm">    ... validate/change dtype, validate flags, ndim, etc ...</span>
<span class="cm">     Could make custom strides here too */</span>
    <span class="n">arr</span> <span class="o">=</span> <span class="n">PyArray_NewFromDescr</span><span class="p">(</span><span class="o">&amp;</span><span class="n">PyArray_Type</span><span class="p">,</span> <span class="n">dtype</span><span class="p">,</span> <span class="n">ndim</span><span class="p">,</span>
                                <span class="n">dims</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">,</span>
                                <span class="n">fortran</span> <span class="o">?</span> <span class="nl">NPY_ARRAY_F_CONTIGUOUS</span> <span class="p">:</span> <span class="mi">0</span><span class="p">,</span>
                                <span class="nb">NULL</span><span class="p">);</span>
    <span class="k">if</span> <span class="p">(</span><span class="n">arr</span> <span class="o">==</span> <span class="nb">NULL</span><span class="p">)</span> <span class="p">{</span>
        <span class="k">return</span> <span class="nb">NULL</span><span class="p">;</span>
    <span class="p">}</span>
    <span class="k">if</span> <span class="p">(</span><span class="n">PyArray_CopyObject</span><span class="p">(</span><span class="n">arr</span><span class="p">,</span> <span class="n">op</span><span class="p">)</span> <span class="o">&lt;</span> <span class="mi">0</span><span class="p">)</span> <span class="p">{</span>
        <span class="n">Py_DECREF</span><span class="p">(</span><span class="n">arr</span><span class="p">);</span>
        <span class="k">return</span> <span class="nb">NULL</span><span class="p">;</span>
    <span class="p">}</span>
<span class="p">}</span>
<span class="k">else</span> <span class="p">{</span>
    <span class="cm">/*</span>
<span class="cm">    ... in this case the other parameters weren&#39;t filled, just</span>
<span class="cm">        validate and possibly copy arr itself ...</span>
<span class="cm">    */</span>
<span class="p">}</span>
<span class="cm">/*</span>
<span class="cm">... use arr ...</span>
<span class="cm">*/</span>
</pre></div>
</div>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_CheckFromAny">
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>* <code class="sig-name descname">PyArray_CheckFromAny</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> op</em>, <a class="reference internal" href="types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>*<em> dtype</em>, int<em> min_depth</em>, int<em> max_depth</em>, int<em> requirements</em>, <a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> context</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_CheckFromAny" title="Permalink to this definition">¶</a></dt>
<dd><p>Nearly identical to <a class="reference internal" href="#c.PyArray_FromAny" title="PyArray_FromAny"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_FromAny</span></code></a> (…) except
<em>requirements</em> can contain <a class="reference internal" href="#c.NPY_ARRAY_NOTSWAPPED" title="NPY_ARRAY_NOTSWAPPED"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_NOTSWAPPED</span></code></a> (over-riding the
specification in <em>dtype</em>) and <a class="reference internal" href="#c.NPY_ARRAY_ELEMENTSTRIDES" title="NPY_ARRAY_ELEMENTSTRIDES"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_ELEMENTSTRIDES</span></code></a> which
indicates that the array should be aligned in the sense that the
strides are multiples of the element size.</p>
<p>In versions 1.6 and earlier of NumPy, the following flags
did not have the _ARRAY_ macro namespace in them. That form
of the constant names is deprecated in 1.7.</p>
</dd></dl>

<dl class="var">
<dt id="c.NPY_ARRAY_NOTSWAPPED">
<code class="sig-name descname">NPY_ARRAY_NOTSWAPPED</code><a class="headerlink" href="#c.NPY_ARRAY_NOTSWAPPED" title="Permalink to this definition">¶</a></dt>
<dd><p>Make sure the returned array has a data-type descriptor that is in
machine byte-order, over-riding any specification in the <em>dtype</em>
argument. Normally, the byte-order requirement is determined by
the <em>dtype</em> argument. If this flag is set and the dtype argument
does not indicate a machine byte-order descriptor (or is NULL and
the object is already an array with a data-type descriptor that is
not in machine byte- order), then a new data-type descriptor is
created and used with its byte-order field set to native.</p>
</dd></dl>

<dl class="var">
<dt id="c.NPY_ARRAY_BEHAVED_NS">
<code class="sig-name descname">NPY_ARRAY_BEHAVED_NS</code><a class="headerlink" href="#c.NPY_ARRAY_BEHAVED_NS" title="Permalink to this definition">¶</a></dt>
<dd><p><a class="reference internal" href="#c.NPY_ARRAY_ALIGNED" title="NPY_ARRAY_ALIGNED"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_ALIGNED</span></code></a> | <a class="reference internal" href="#c.NPY_ARRAY_WRITEABLE" title="NPY_ARRAY_WRITEABLE"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_WRITEABLE</span></code></a> | <a class="reference internal" href="#c.NPY_ARRAY_NOTSWAPPED" title="NPY_ARRAY_NOTSWAPPED"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_NOTSWAPPED</span></code></a></p>
</dd></dl>

<dl class="var">
<dt id="c.NPY_ARRAY_ELEMENTSTRIDES">
<code class="sig-name descname">NPY_ARRAY_ELEMENTSTRIDES</code><a class="headerlink" href="#c.NPY_ARRAY_ELEMENTSTRIDES" title="Permalink to this definition">¶</a></dt>
<dd><p>Make sure the returned array has strides that are multiples of the
element size.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_FromArray">
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>* <code class="sig-name descname">PyArray_FromArray</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> op</em>, <a class="reference internal" href="types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>*<em> newtype</em>, int<em> requirements</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_FromArray" title="Permalink to this definition">¶</a></dt>
<dd><p>Special case of <a class="reference internal" href="#c.PyArray_FromAny" title="PyArray_FromAny"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_FromAny</span></code></a> for when <em>op</em> is already an
array but it needs to be of a specific <em>newtype</em> (including
byte-order) or has certain <em>requirements</em>.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_FromStructInterface">
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>* <code class="sig-name descname">PyArray_FromStructInterface</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> op</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_FromStructInterface" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns an ndarray object from a Python object that exposes the
<code class="xref py py-obj docutils literal notranslate"><span class="pre">__array_struct__</span></code> attribute and follows the array interface
protocol. If the object does not contain this attribute then a
borrowed reference to <a class="reference external" href="https://docs.python.org/dev/c-api/object.html#c.Py_NotImplemented" title="(in Python v3.9)"><code class="xref c c-data docutils literal notranslate"><span class="pre">Py_NotImplemented</span></code></a> is returned.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_FromInterface">
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>* <code class="sig-name descname">PyArray_FromInterface</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> op</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_FromInterface" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns an ndarray object from a Python object that exposes the
<a class="reference internal" href="../arrays.interface.html#__array_interface__" title="__array_interface__"><code class="xref py py-obj docutils literal notranslate"><span class="pre">__array_interface__</span></code></a> attribute following the array interface
protocol. If the object does not contain this attribute then a
borrowed reference to <a class="reference external" href="https://docs.python.org/dev/c-api/object.html#c.Py_NotImplemented" title="(in Python v3.9)"><code class="xref c c-data docutils literal notranslate"><span class="pre">Py_NotImplemented</span></code></a> is returned.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_FromArrayAttr">
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>* <code class="sig-name descname">PyArray_FromArrayAttr</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> op</em>, <a class="reference internal" href="types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>*<em> dtype</em>, <a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> context</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_FromArrayAttr" title="Permalink to this definition">¶</a></dt>
<dd><p>Return an ndarray object from a Python object that exposes the
<a class="reference internal" href="../arrays.classes.html#numpy.class.__array__" title="numpy.class.__array__"><code class="xref py py-obj docutils literal notranslate"><span class="pre">__array__</span></code></a> method. The <a class="reference internal" href="../arrays.classes.html#numpy.class.__array__" title="numpy.class.__array__"><code class="xref py py-obj docutils literal notranslate"><span class="pre">__array__</span></code></a> method can take 0, 1, or 2
arguments ([dtype, context]) where <em>context</em> is used to pass
information about where the <a class="reference internal" href="../arrays.classes.html#numpy.class.__array__" title="numpy.class.__array__"><code class="xref py py-obj docutils literal notranslate"><span class="pre">__array__</span></code></a> method is being called
from (currently only used in ufuncs).</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_ContiguousFromAny">
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>* <code class="sig-name descname">PyArray_ContiguousFromAny</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> op</em>, int<em> typenum</em>, int<em> min_depth</em>, int<em> max_depth</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_ContiguousFromAny" title="Permalink to this definition">¶</a></dt>
<dd><p>This function returns a (C-style) contiguous and behaved function
array from any nested sequence or array interface exporting
object, <em>op</em>, of (non-flexible) type given by the enumerated
<em>typenum</em>, of minimum depth <em>min_depth</em>, and of maximum depth
<em>max_depth</em>. Equivalent to a call to <a class="reference internal" href="#c.PyArray_FromAny" title="PyArray_FromAny"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_FromAny</span></code></a> with
requirements set to <a class="reference internal" href="#c.NPY_ARRAY_DEFAULT" title="NPY_ARRAY_DEFAULT"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_DEFAULT</span></code></a> and the type_num member of the
type argument set to <em>typenum</em>.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_FromObject">
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a> *<code class="sig-name descname">PyArray_FromObject</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a><em> *op</em>, int<em> typenum</em>, int<em> min_depth</em>, int<em> max_depth</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_FromObject" title="Permalink to this definition">¶</a></dt>
<dd><p>Return an aligned and in native-byteorder array from any nested
sequence or array-interface exporting object, op, of a type given by
the enumerated typenum. The minimum number of dimensions the array can
have is given by min_depth while the maximum is max_depth. This is
equivalent to a call to <a class="reference internal" href="#c.PyArray_FromAny" title="PyArray_FromAny"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_FromAny</span></code></a> with requirements set to
BEHAVED.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_EnsureArray">
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>* <code class="sig-name descname">PyArray_EnsureArray</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> op</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_EnsureArray" title="Permalink to this definition">¶</a></dt>
<dd><p>This function <strong>steals a reference</strong> to <code class="docutils literal notranslate"><span class="pre">op</span></code> and makes sure that
<code class="docutils literal notranslate"><span class="pre">op</span></code> is a base-class ndarray. It special cases array scalars,
but otherwise calls <a class="reference internal" href="#c.PyArray_FromAny" title="PyArray_FromAny"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_FromAny</span></code></a> ( <code class="docutils literal notranslate"><span class="pre">op</span></code>, NULL, 0, 0,
<a class="reference internal" href="#c.NPY_ARRAY_ENSUREARRAY" title="NPY_ARRAY_ENSUREARRAY"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_ENSUREARRAY</span></code></a>, NULL).</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_FromString">
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>* <code class="sig-name descname">PyArray_FromString</code><span class="sig-paren">(</span>char*<em> string</em>, <a class="reference internal" href="dtype.html#c.npy_intp" title="npy_intp">npy_intp</a><em> slen</em>, <a class="reference internal" href="types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>*<em> dtype</em>, <a class="reference internal" href="dtype.html#c.npy_intp" title="npy_intp">npy_intp</a><em> num</em>, char*<em> sep</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_FromString" title="Permalink to this definition">¶</a></dt>
<dd><p>Construct a one-dimensional ndarray of a single type from a binary
or (ASCII) text <code class="docutils literal notranslate"><span class="pre">string</span></code> of length <code class="docutils literal notranslate"><span class="pre">slen</span></code>. The data-type of
the array to-be-created is given by <code class="docutils literal notranslate"><span class="pre">dtype</span></code>. If num is -1, then
<strong>copy</strong> the entire string and return an appropriately sized
array, otherwise, <code class="docutils literal notranslate"><span class="pre">num</span></code> is the number of items to <strong>copy</strong> from
the string. If <code class="docutils literal notranslate"><span class="pre">sep</span></code> is NULL (or “”), then interpret the string
as bytes of binary data, otherwise convert the sub-strings
separated by <code class="docutils literal notranslate"><span class="pre">sep</span></code> to items of data-type <code class="docutils literal notranslate"><span class="pre">dtype</span></code>. Some
data-types may not be readable in text mode and an error will be
raised if that occurs. All errors return NULL.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_FromFile">
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>* <code class="sig-name descname">PyArray_FromFile</code><span class="sig-paren">(</span>FILE*<em> fp</em>, <a class="reference internal" href="types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>*<em> dtype</em>, <a class="reference internal" href="dtype.html#c.npy_intp" title="npy_intp">npy_intp</a><em> num</em>, char*<em> sep</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_FromFile" title="Permalink to this definition">¶</a></dt>
<dd><p>Construct a one-dimensional ndarray of a single type from a binary
or text file. The open file pointer is <code class="docutils literal notranslate"><span class="pre">fp</span></code>, the data-type of
the array to be created is given by <code class="docutils literal notranslate"><span class="pre">dtype</span></code>. This must match
the data in the file. If <code class="docutils literal notranslate"><span class="pre">num</span></code> is -1, then read until the end of
the file and return an appropriately sized array, otherwise,
<code class="docutils literal notranslate"><span class="pre">num</span></code> is the number of items to read. If <code class="docutils literal notranslate"><span class="pre">sep</span></code> is NULL (or
“”), then read from the file in binary mode, otherwise read from
the file in text mode with <code class="docutils literal notranslate"><span class="pre">sep</span></code> providing the item
separator. Some array types cannot be read in text mode in which
case an error is raised.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_FromBuffer">
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>* <code class="sig-name descname">PyArray_FromBuffer</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> buf</em>, <a class="reference internal" href="types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>*<em> dtype</em>, <a class="reference internal" href="dtype.html#c.npy_intp" title="npy_intp">npy_intp</a><em> count</em>, <a class="reference internal" href="dtype.html#c.npy_intp" title="npy_intp">npy_intp</a><em> offset</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_FromBuffer" title="Permalink to this definition">¶</a></dt>
<dd><p>Construct a one-dimensional ndarray of a single type from an
object, <code class="docutils literal notranslate"><span class="pre">buf</span></code>, that exports the (single-segment) buffer protocol
(or has an attribute __buffer__ that returns an object that
exports the buffer protocol). A writeable buffer will be tried
first followed by a read- only buffer. The <a class="reference internal" href="#c.NPY_ARRAY_WRITEABLE" title="NPY_ARRAY_WRITEABLE"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_WRITEABLE</span></code></a>
flag of the returned array will reflect which one was
successful. The data is assumed to start at <code class="docutils literal notranslate"><span class="pre">offset</span></code> bytes from
the start of the memory location for the object. The type of the
data in the buffer will be interpreted depending on the data- type
descriptor, <code class="docutils literal notranslate"><span class="pre">dtype.</span></code> If <code class="docutils literal notranslate"><span class="pre">count</span></code> is negative then it will be
determined from the size of the buffer and the requested itemsize,
otherwise, <code class="docutils literal notranslate"><span class="pre">count</span></code> represents how many elements should be
converted from the buffer.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_CopyInto">
int <code class="sig-name descname">PyArray_CopyInto</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> dest</em>, <a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> src</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_CopyInto" title="Permalink to this definition">¶</a></dt>
<dd><p>Copy from the source array, <code class="docutils literal notranslate"><span class="pre">src</span></code>, into the destination array,
<code class="docutils literal notranslate"><span class="pre">dest</span></code>, performing a data-type conversion if necessary. If an
error occurs return -1 (otherwise 0). The shape of <code class="docutils literal notranslate"><span class="pre">src</span></code> must be
broadcastable to the shape of <code class="docutils literal notranslate"><span class="pre">dest</span></code>. The data areas of dest
and src must not overlap.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_MoveInto">
int <code class="sig-name descname">PyArray_MoveInto</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> dest</em>, <a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> src</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_MoveInto" title="Permalink to this definition">¶</a></dt>
<dd><p>Move data from the source array, <code class="docutils literal notranslate"><span class="pre">src</span></code>, into the destination
array, <code class="docutils literal notranslate"><span class="pre">dest</span></code>, performing a data-type conversion if
necessary. If an error occurs return -1 (otherwise 0). The shape
of <code class="docutils literal notranslate"><span class="pre">src</span></code> must be broadcastable to the shape of <code class="docutils literal notranslate"><span class="pre">dest</span></code>. The
data areas of dest and src may overlap.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_GETCONTIGUOUS">
<a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>* <code class="sig-name descname">PyArray_GETCONTIGUOUS</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> op</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_GETCONTIGUOUS" title="Permalink to this definition">¶</a></dt>
<dd><p>If <code class="docutils literal notranslate"><span class="pre">op</span></code> is already (C-style) contiguous and well-behaved then
just return a reference, otherwise return a (contiguous and
well-behaved) copy of the array. The parameter op must be a
(sub-class of an) ndarray and no checking for that is done.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_FROM_O">
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>* <code class="sig-name descname">PyArray_FROM_O</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> obj</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_FROM_O" title="Permalink to this definition">¶</a></dt>
<dd><p>Convert <code class="docutils literal notranslate"><span class="pre">obj</span></code> to an ndarray. The argument can be any nested
sequence or object that exports the array interface. This is a
macro form of <a class="reference internal" href="#c.PyArray_FromAny" title="PyArray_FromAny"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_FromAny</span></code></a> using <code class="docutils literal notranslate"><span class="pre">NULL</span></code>, 0, 0, 0 for the
other arguments. Your code must be able to handle any data-type
descriptor and any combination of data-flags to use this macro.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_FROM_OF">
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>* <code class="sig-name descname">PyArray_FROM_OF</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> obj</em>, int<em> requirements</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_FROM_OF" title="Permalink to this definition">¶</a></dt>
<dd><p>Similar to <a class="reference internal" href="#c.PyArray_FROM_O" title="PyArray_FROM_O"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_FROM_O</span></code></a> except it can take an argument
of <em>requirements</em> indicating properties the resulting array must
have. Available requirements that can be enforced are
<a class="reference internal" href="#c.NPY_ARRAY_C_CONTIGUOUS" title="NPY_ARRAY_C_CONTIGUOUS"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_C_CONTIGUOUS</span></code></a>, <a class="reference internal" href="#c.NPY_ARRAY_F_CONTIGUOUS" title="NPY_ARRAY_F_CONTIGUOUS"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_F_CONTIGUOUS</span></code></a>,
<a class="reference internal" href="#c.NPY_ARRAY_ALIGNED" title="NPY_ARRAY_ALIGNED"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_ALIGNED</span></code></a>, <a class="reference internal" href="#c.NPY_ARRAY_WRITEABLE" title="NPY_ARRAY_WRITEABLE"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_WRITEABLE</span></code></a>,
<a class="reference internal" href="#c.NPY_ARRAY_NOTSWAPPED" title="NPY_ARRAY_NOTSWAPPED"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_NOTSWAPPED</span></code></a>, <a class="reference internal" href="#c.NPY_ARRAY_ENSURECOPY" title="NPY_ARRAY_ENSURECOPY"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_ENSURECOPY</span></code></a>,
<a class="reference internal" href="#c.NPY_ARRAY_WRITEBACKIFCOPY" title="NPY_ARRAY_WRITEBACKIFCOPY"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_WRITEBACKIFCOPY</span></code></a>, <a class="reference internal" href="#c.NPY_ARRAY_UPDATEIFCOPY" title="NPY_ARRAY_UPDATEIFCOPY"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_UPDATEIFCOPY</span></code></a>,
<a class="reference internal" href="#c.NPY_ARRAY_FORCECAST" title="NPY_ARRAY_FORCECAST"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_FORCECAST</span></code></a>, and
<a class="reference internal" href="#c.NPY_ARRAY_ENSUREARRAY" title="NPY_ARRAY_ENSUREARRAY"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_ENSUREARRAY</span></code></a>. Standard combinations of flags can also
be used:</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_FROM_OT">
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>* <code class="sig-name descname">PyArray_FROM_OT</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> obj</em>, int<em> typenum</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_FROM_OT" title="Permalink to this definition">¶</a></dt>
<dd><p>Similar to <a class="reference internal" href="#c.PyArray_FROM_O" title="PyArray_FROM_O"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_FROM_O</span></code></a> except it can take an argument of
<em>typenum</em> specifying the type-number the returned array.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_FROM_OTF">
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>* <code class="sig-name descname">PyArray_FROM_OTF</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> obj</em>, int<em> typenum</em>, int<em> requirements</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_FROM_OTF" title="Permalink to this definition">¶</a></dt>
<dd><p>Combination of <a class="reference internal" href="#c.PyArray_FROM_OF" title="PyArray_FROM_OF"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_FROM_OF</span></code></a> and <a class="reference internal" href="#c.PyArray_FROM_OT" title="PyArray_FROM_OT"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_FROM_OT</span></code></a>
allowing both a <em>typenum</em> and a <em>flags</em> argument to be provided.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_FROMANY">
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>* <code class="sig-name descname">PyArray_FROMANY</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> obj</em>, int<em> typenum</em>, int<em> min</em>, int<em> max</em>, int<em> requirements</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_FROMANY" title="Permalink to this definition">¶</a></dt>
<dd><p>Similar to <a class="reference internal" href="#c.PyArray_FromAny" title="PyArray_FromAny"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_FromAny</span></code></a> except the data-type is
specified using a typenumber. <a class="reference internal" href="#c.PyArray_DescrFromType" title="PyArray_DescrFromType"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_DescrFromType</span></code></a>
(<em>typenum</em>) is passed directly to <a class="reference internal" href="#c.PyArray_FromAny" title="PyArray_FromAny"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_FromAny</span></code></a>. This
macro also adds <a class="reference internal" href="#c.NPY_ARRAY_DEFAULT" title="NPY_ARRAY_DEFAULT"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_DEFAULT</span></code></a> to requirements if
<a class="reference internal" href="#c.NPY_ARRAY_ENSURECOPY" title="NPY_ARRAY_ENSURECOPY"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_ENSURECOPY</span></code></a> is passed in as requirements.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_CheckAxis">
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a> *<code class="sig-name descname">PyArray_CheckAxis</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> obj</em>, int*<em> axis</em>, int<em> requirements</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_CheckAxis" title="Permalink to this definition">¶</a></dt>
<dd><p>Encapsulate the functionality of functions and methods that take
the axis= keyword and work properly with None as the axis
argument. The input array is <code class="docutils literal notranslate"><span class="pre">obj</span></code>, while <code class="docutils literal notranslate"><span class="pre">*axis</span></code> is a
converted integer (so that &gt;=MAXDIMS is the None value), and
<code class="docutils literal notranslate"><span class="pre">requirements</span></code> gives the needed properties of <code class="docutils literal notranslate"><span class="pre">obj</span></code>. The
output is a converted version of the input so that requirements
are met and if needed a flattening has occurred. On output
negative values of <code class="docutils literal notranslate"><span class="pre">*axis</span></code> are converted and the new value is
checked to ensure consistency with the shape of <code class="docutils literal notranslate"><span class="pre">obj</span></code>.</p>
</dd></dl>

</div>
</div>
<div class="section" id="dealing-with-types">
<h2>Dealing with types<a class="headerlink" href="#dealing-with-types" title="Permalink to this headline">¶</a></h2>
<div class="section" id="general-check-of-python-type">
<h3>General check of Python Type<a class="headerlink" href="#general-check-of-python-type" title="Permalink to this headline">¶</a></h3>
<dl class="function">
<dt id="c.PyArray_Check">
<code class="sig-name descname">PyArray_Check</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a><em> *op</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_Check" title="Permalink to this definition">¶</a></dt>
<dd><p>Evaluates true if <em>op</em> is a Python object whose type is a sub-type
of <a class="reference internal" href="types-and-structures.html#c.PyArray_Type" title="PyArray_Type"><code class="xref c c-data docutils literal notranslate"><span class="pre">PyArray_Type</span></code></a>.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_CheckExact">
<code class="sig-name descname">PyArray_CheckExact</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a><em> *op</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_CheckExact" title="Permalink to this definition">¶</a></dt>
<dd><p>Evaluates true if <em>op</em> is a Python object with type
<a class="reference internal" href="types-and-structures.html#c.PyArray_Type" title="PyArray_Type"><code class="xref c c-data docutils literal notranslate"><span class="pre">PyArray_Type</span></code></a>.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_HasArrayInterface">
<code class="sig-name descname">PyArray_HasArrayInterface</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a><em> *op</em>, <a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a><em> *out</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_HasArrayInterface" title="Permalink to this definition">¶</a></dt>
<dd><p>If <code class="docutils literal notranslate"><span class="pre">op</span></code> implements any part of the array interface, then <code class="docutils literal notranslate"><span class="pre">out</span></code>
will contain a new reference to the newly created ndarray using
the interface or <code class="docutils literal notranslate"><span class="pre">out</span></code> will contain <code class="docutils literal notranslate"><span class="pre">NULL</span></code> if an error during
conversion occurs. Otherwise, out will contain a borrowed
reference to <a class="reference external" href="https://docs.python.org/dev/c-api/object.html#c.Py_NotImplemented" title="(in Python v3.9)"><code class="xref c c-data docutils literal notranslate"><span class="pre">Py_NotImplemented</span></code></a> and no error condition is set.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_HasArrayInterfaceType">
<code class="sig-name descname">PyArray_HasArrayInterfaceType</code><span class="sig-paren">(</span>op, type, context, out<span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_HasArrayInterfaceType" title="Permalink to this definition">¶</a></dt>
<dd><p>If <code class="docutils literal notranslate"><span class="pre">op</span></code> implements any part of the array interface, then <code class="docutils literal notranslate"><span class="pre">out</span></code>
will contain a new reference to the newly created ndarray using
the interface or <code class="docutils literal notranslate"><span class="pre">out</span></code> will contain <code class="docutils literal notranslate"><span class="pre">NULL</span></code> if an error during
conversion occurs. Otherwise, out will contain a borrowed
reference to Py_NotImplemented and no error condition is set.
This version allows setting of the type and context in the part of
the array interface that looks for the <a class="reference internal" href="../arrays.classes.html#numpy.class.__array__" title="numpy.class.__array__"><code class="xref py py-obj docutils literal notranslate"><span class="pre">__array__</span></code></a> attribute.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_IsZeroDim">
<code class="sig-name descname">PyArray_IsZeroDim</code><span class="sig-paren">(</span>op<span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_IsZeroDim" title="Permalink to this definition">¶</a></dt>
<dd><p>Evaluates true if <em>op</em> is an instance of (a subclass of)
<a class="reference internal" href="types-and-structures.html#c.PyArray_Type" title="PyArray_Type"><code class="xref c c-data docutils literal notranslate"><span class="pre">PyArray_Type</span></code></a> and has 0 dimensions.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_IsScalar">
<code class="sig-name descname">PyArray_IsScalar</code><span class="sig-paren">(</span>op, cls<span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_IsScalar" title="Permalink to this definition">¶</a></dt>
<dd><p>Evaluates true if <em>op</em> is an instance of <code class="xref c c-data docutils literal notranslate"><span class="pre">Py{cls}ArrType_Type</span></code>.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_CheckScalar">
<code class="sig-name descname">PyArray_CheckScalar</code><span class="sig-paren">(</span>op<span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_CheckScalar" title="Permalink to this definition">¶</a></dt>
<dd><p>Evaluates true if <em>op</em> is either an array scalar (an instance of a
sub-type of <code class="xref c c-data docutils literal notranslate"><span class="pre">PyGenericArr_Type</span></code> ), or an instance of (a
sub-class of) <a class="reference internal" href="types-and-structures.html#c.PyArray_Type" title="PyArray_Type"><code class="xref c c-data docutils literal notranslate"><span class="pre">PyArray_Type</span></code></a> whose dimensionality is 0.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_IsPythonNumber">
<code class="sig-name descname">PyArray_IsPythonNumber</code><span class="sig-paren">(</span>op<span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_IsPythonNumber" title="Permalink to this definition">¶</a></dt>
<dd><p>Evaluates true if <em>op</em> is an instance of a builtin numeric type (int,
float, complex, long, bool)</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_IsPythonScalar">
<code class="sig-name descname">PyArray_IsPythonScalar</code><span class="sig-paren">(</span>op<span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_IsPythonScalar" title="Permalink to this definition">¶</a></dt>
<dd><p>Evaluates true if <em>op</em> is a builtin Python scalar object (int,
float, complex, str, unicode, long, bool).</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_IsAnyScalar">
<code class="sig-name descname">PyArray_IsAnyScalar</code><span class="sig-paren">(</span>op<span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_IsAnyScalar" title="Permalink to this definition">¶</a></dt>
<dd><p>Evaluates true if <em>op</em> is either a Python scalar object (see
<a class="reference internal" href="#c.PyArray_IsPythonScalar" title="PyArray_IsPythonScalar"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_IsPythonScalar</span></code></a>) or an array scalar (an instance of a sub-
type of <code class="xref c c-data docutils literal notranslate"><span class="pre">PyGenericArr_Type</span></code> ).</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_CheckAnyScalar">
<code class="sig-name descname">PyArray_CheckAnyScalar</code><span class="sig-paren">(</span>op<span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_CheckAnyScalar" title="Permalink to this definition">¶</a></dt>
<dd><p>Evaluates true if <em>op</em> is a Python scalar object (see
<a class="reference internal" href="#c.PyArray_IsPythonScalar" title="PyArray_IsPythonScalar"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_IsPythonScalar</span></code></a>), an array scalar (an instance of a
sub-type of <code class="xref c c-data docutils literal notranslate"><span class="pre">PyGenericArr_Type</span></code>) or an instance of a sub-type of
<a class="reference internal" href="types-and-structures.html#c.PyArray_Type" title="PyArray_Type"><code class="xref c c-data docutils literal notranslate"><span class="pre">PyArray_Type</span></code></a> whose dimensionality is 0.</p>
</dd></dl>

</div>
<div class="section" id="data-type-checking">
<h3>Data-type checking<a class="headerlink" href="#data-type-checking" title="Permalink to this headline">¶</a></h3>
<p>For the typenum macros, the argument is an integer representing an
enumerated array data type. For the array type checking macros the
argument must be a <a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyObject</span> <span class="pre">*</span></code></a> that can be directly interpreted as a
<a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyArrayObject</span> <span class="pre">*</span></code></a>.</p>
<dl class="function">
<dt id="c.PyTypeNum_ISUNSIGNED">
<code class="sig-name descname">PyTypeNum_ISUNSIGNED</code><span class="sig-paren">(</span>int<em> num</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyTypeNum_ISUNSIGNED" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="function">
<dt id="c.PyDataType_ISUNSIGNED">
<code class="sig-name descname">PyDataType_ISUNSIGNED</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a><em> *descr</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyDataType_ISUNSIGNED" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="function">
<dt id="c.PyArray_ISUNSIGNED">
<code class="sig-name descname">PyArray_ISUNSIGNED</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a><em> *obj</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_ISUNSIGNED" title="Permalink to this definition">¶</a></dt>
<dd><p>Type represents an unsigned integer.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyTypeNum_ISSIGNED">
<code class="sig-name descname">PyTypeNum_ISSIGNED</code><span class="sig-paren">(</span>int<em> num</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyTypeNum_ISSIGNED" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="function">
<dt id="c.PyDataType_ISSIGNED">
<code class="sig-name descname">PyDataType_ISSIGNED</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a><em> *descr</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyDataType_ISSIGNED" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="function">
<dt id="c.PyArray_ISSIGNED">
<code class="sig-name descname">PyArray_ISSIGNED</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a><em> *obj</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_ISSIGNED" title="Permalink to this definition">¶</a></dt>
<dd><p>Type represents a signed integer.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyTypeNum_ISINTEGER">
<code class="sig-name descname">PyTypeNum_ISINTEGER</code><span class="sig-paren">(</span>int<em> num</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyTypeNum_ISINTEGER" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="function">
<dt id="c.PyDataType_ISINTEGER">
<code class="sig-name descname">PyDataType_ISINTEGER</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>*<em> descr</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyDataType_ISINTEGER" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="function">
<dt id="c.PyArray_ISINTEGER">
<code class="sig-name descname">PyArray_ISINTEGER</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a><em> *obj</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_ISINTEGER" title="Permalink to this definition">¶</a></dt>
<dd><p>Type represents any integer.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyTypeNum_ISFLOAT">
<code class="sig-name descname">PyTypeNum_ISFLOAT</code><span class="sig-paren">(</span>int<em> num</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyTypeNum_ISFLOAT" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="function">
<dt id="c.PyDataType_ISFLOAT">
<code class="sig-name descname">PyDataType_ISFLOAT</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>*<em> descr</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyDataType_ISFLOAT" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="function">
<dt id="c.PyArray_ISFLOAT">
<code class="sig-name descname">PyArray_ISFLOAT</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a><em> *obj</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_ISFLOAT" title="Permalink to this definition">¶</a></dt>
<dd><p>Type represents any floating point number.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyTypeNum_ISCOMPLEX">
<code class="sig-name descname">PyTypeNum_ISCOMPLEX</code><span class="sig-paren">(</span>int<em> num</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyTypeNum_ISCOMPLEX" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="function">
<dt id="c.PyDataType_ISCOMPLEX">
<code class="sig-name descname">PyDataType_ISCOMPLEX</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>*<em> descr</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyDataType_ISCOMPLEX" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="function">
<dt id="c.PyArray_ISCOMPLEX">
<code class="sig-name descname">PyArray_ISCOMPLEX</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a><em> *obj</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_ISCOMPLEX" title="Permalink to this definition">¶</a></dt>
<dd><p>Type represents any complex floating point number.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyTypeNum_ISNUMBER">
<code class="sig-name descname">PyTypeNum_ISNUMBER</code><span class="sig-paren">(</span>int<em> num</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyTypeNum_ISNUMBER" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="function">
<dt id="c.PyDataType_ISNUMBER">
<code class="sig-name descname">PyDataType_ISNUMBER</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>*<em> descr</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyDataType_ISNUMBER" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="function">
<dt id="c.PyArray_ISNUMBER">
<code class="sig-name descname">PyArray_ISNUMBER</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a><em> *obj</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_ISNUMBER" title="Permalink to this definition">¶</a></dt>
<dd><p>Type represents any integer, floating point, or complex floating point
number.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyTypeNum_ISSTRING">
<code class="sig-name descname">PyTypeNum_ISSTRING</code><span class="sig-paren">(</span>int<em> num</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyTypeNum_ISSTRING" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="function">
<dt id="c.PyDataType_ISSTRING">
<code class="sig-name descname">PyDataType_ISSTRING</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>*<em> descr</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyDataType_ISSTRING" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="function">
<dt id="c.PyArray_ISSTRING">
<code class="sig-name descname">PyArray_ISSTRING</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a><em> *obj</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_ISSTRING" title="Permalink to this definition">¶</a></dt>
<dd><p>Type represents a string data type.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyTypeNum_ISPYTHON">
<code class="sig-name descname">PyTypeNum_ISPYTHON</code><span class="sig-paren">(</span>int<em> num</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyTypeNum_ISPYTHON" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="function">
<dt id="c.PyDataType_ISPYTHON">
<code class="sig-name descname">PyDataType_ISPYTHON</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>*<em> descr</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyDataType_ISPYTHON" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="function">
<dt id="c.PyArray_ISPYTHON">
<code class="sig-name descname">PyArray_ISPYTHON</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a><em> *obj</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_ISPYTHON" title="Permalink to this definition">¶</a></dt>
<dd><p>Type represents an enumerated type corresponding to one of the
standard Python scalar (bool, int, float, or complex).</p>
</dd></dl>

<dl class="function">
<dt id="c.PyTypeNum_ISFLEXIBLE">
<code class="sig-name descname">PyTypeNum_ISFLEXIBLE</code><span class="sig-paren">(</span>int<em> num</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyTypeNum_ISFLEXIBLE" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="function">
<dt id="c.PyDataType_ISFLEXIBLE">
<code class="sig-name descname">PyDataType_ISFLEXIBLE</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>*<em> descr</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyDataType_ISFLEXIBLE" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="function">
<dt id="c.PyArray_ISFLEXIBLE">
<code class="sig-name descname">PyArray_ISFLEXIBLE</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a><em> *obj</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_ISFLEXIBLE" title="Permalink to this definition">¶</a></dt>
<dd><p>Type represents one of the flexible array types ( <a class="reference internal" href="dtype.html#c.NPY_STRING" title="NPY_STRING"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_STRING</span></code></a>,
<a class="reference internal" href="dtype.html#c.NPY_UNICODE" title="NPY_UNICODE"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_UNICODE</span></code></a>, or <a class="reference internal" href="dtype.html#c.NPY_VOID" title="NPY_VOID"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_VOID</span></code></a> ).</p>
</dd></dl>

<dl class="function">
<dt>
<code class="sig-name descname">PyDataType_ISUNSIZED(PyArray_Descr* descr):</code></dt>
<dd><p>Type has no size information attached, and can be resized. Should only be
called on flexible dtypes. Types that are attached to an array will always
be sized, hence the array form of this macro not existing.</p>
<div class="versionchanged">
<p><span class="versionmodified changed">Changed in version 1.18.</span></p>
</div>
<p>For structured datatypes with no fields this function now returns False.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyTypeNum_ISUSERDEF">
<code class="sig-name descname">PyTypeNum_ISUSERDEF</code><span class="sig-paren">(</span>int<em> num</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyTypeNum_ISUSERDEF" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="function">
<dt id="c.PyDataType_ISUSERDEF">
<code class="sig-name descname">PyDataType_ISUSERDEF</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>*<em> descr</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyDataType_ISUSERDEF" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="function">
<dt id="c.PyArray_ISUSERDEF">
<code class="sig-name descname">PyArray_ISUSERDEF</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a><em> *obj</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_ISUSERDEF" title="Permalink to this definition">¶</a></dt>
<dd><p>Type represents a user-defined type.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyTypeNum_ISEXTENDED">
<code class="sig-name descname">PyTypeNum_ISEXTENDED</code><span class="sig-paren">(</span>int<em> num</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyTypeNum_ISEXTENDED" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="function">
<dt id="c.PyDataType_ISEXTENDED">
<code class="sig-name descname">PyDataType_ISEXTENDED</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>*<em> descr</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyDataType_ISEXTENDED" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="function">
<dt id="c.PyArray_ISEXTENDED">
<code class="sig-name descname">PyArray_ISEXTENDED</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a><em> *obj</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_ISEXTENDED" title="Permalink to this definition">¶</a></dt>
<dd><p>Type is either flexible or user-defined.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyTypeNum_ISOBJECT">
<code class="sig-name descname">PyTypeNum_ISOBJECT</code><span class="sig-paren">(</span>int<em> num</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyTypeNum_ISOBJECT" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="function">
<dt id="c.PyDataType_ISOBJECT">
<code class="sig-name descname">PyDataType_ISOBJECT</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>*<em> descr</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyDataType_ISOBJECT" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="function">
<dt id="c.PyArray_ISOBJECT">
<code class="sig-name descname">PyArray_ISOBJECT</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a><em> *obj</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_ISOBJECT" title="Permalink to this definition">¶</a></dt>
<dd><p>Type represents object data type.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyTypeNum_ISBOOL">
<code class="sig-name descname">PyTypeNum_ISBOOL</code><span class="sig-paren">(</span>int<em> num</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyTypeNum_ISBOOL" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="function">
<dt id="c.PyDataType_ISBOOL">
<code class="sig-name descname">PyDataType_ISBOOL</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>*<em> descr</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyDataType_ISBOOL" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="function">
<dt id="c.PyArray_ISBOOL">
<code class="sig-name descname">PyArray_ISBOOL</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a><em> *obj</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_ISBOOL" title="Permalink to this definition">¶</a></dt>
<dd><p>Type represents Boolean data type.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyDataType_HASFIELDS">
<code class="sig-name descname">PyDataType_HASFIELDS</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>*<em> descr</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyDataType_HASFIELDS" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="function">
<dt id="c.PyArray_HASFIELDS">
<code class="sig-name descname">PyArray_HASFIELDS</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a><em> *obj</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_HASFIELDS" title="Permalink to this definition">¶</a></dt>
<dd><p>Type has fields associated with it.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_ISNOTSWAPPED">
<code class="sig-name descname">PyArray_ISNOTSWAPPED</code><span class="sig-paren">(</span>m<span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_ISNOTSWAPPED" title="Permalink to this definition">¶</a></dt>
<dd><p>Evaluates true if the data area of the ndarray <em>m</em> is in machine
byte-order according to the array’s data-type descriptor.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_ISBYTESWAPPED">
<code class="sig-name descname">PyArray_ISBYTESWAPPED</code><span class="sig-paren">(</span>m<span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_ISBYTESWAPPED" title="Permalink to this definition">¶</a></dt>
<dd><p>Evaluates true if the data area of the ndarray <em>m</em> is <strong>not</strong> in
machine byte-order according to the array’s data-type descriptor.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_EquivTypes">
Bool <code class="sig-name descname">PyArray_EquivTypes</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>*<em> type1</em>, <a class="reference internal" href="types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>*<em> type2</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_EquivTypes" title="Permalink to this definition">¶</a></dt>
<dd><p>Return <a class="reference internal" href="#c.NPY_TRUE" title="NPY_TRUE"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_TRUE</span></code></a> if <em>type1</em> and <em>type2</em> actually represent
equivalent types for this platform (the fortran member of each
type is ignored). For example, on 32-bit platforms,
<a class="reference internal" href="dtype.html#c.NPY_LONG" title="NPY_LONG"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_LONG</span></code></a> and <a class="reference internal" href="dtype.html#c.NPY_INT" title="NPY_INT"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_INT</span></code></a> are equivalent. Otherwise
return <a class="reference internal" href="#c.NPY_FALSE" title="NPY_FALSE"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_FALSE</span></code></a>.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_EquivArrTypes">
Bool <code class="sig-name descname">PyArray_EquivArrTypes</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> a1</em>, <a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a> *<em> a2</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_EquivArrTypes" title="Permalink to this definition">¶</a></dt>
<dd><p>Return <a class="reference internal" href="#c.NPY_TRUE" title="NPY_TRUE"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_TRUE</span></code></a> if <em>a1</em> and <em>a2</em> are arrays with equivalent
types for this platform.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_EquivTypenums">
Bool <code class="sig-name descname">PyArray_EquivTypenums</code><span class="sig-paren">(</span>int<em> typenum1</em>, int<em> typenum2</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_EquivTypenums" title="Permalink to this definition">¶</a></dt>
<dd><p>Special case of <a class="reference internal" href="#c.PyArray_EquivTypes" title="PyArray_EquivTypes"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_EquivTypes</span></code></a> (…) that does not accept
flexible data types but may be easier to call.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_EquivByteorders">
int <code class="sig-name descname">PyArray_EquivByteorders</code><span class="sig-paren">(</span>{byteorder}<em> b1</em>, {byteorder}<em> b2</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_EquivByteorders" title="Permalink to this definition">¶</a></dt>
<dd><p>True if byteorder characters ( <code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_LITTLE</span></code>,
<code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_BIG</span></code>, <code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_NATIVE</span></code>, <code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_IGNORE</span></code> ) are
either equal or equivalent as to their specification of a native
byte order. Thus, on a little-endian machine <code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_LITTLE</span></code>
and <code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_NATIVE</span></code> are equivalent where they are not
equivalent on a big-endian machine.</p>
</dd></dl>

</div>
<div class="section" id="converting-data-types">
<h3>Converting data types<a class="headerlink" href="#converting-data-types" title="Permalink to this headline">¶</a></h3>
<dl class="function">
<dt id="c.PyArray_Cast">
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>* <code class="sig-name descname">PyArray_Cast</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> arr</em>, int<em> typenum</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_Cast" title="Permalink to this definition">¶</a></dt>
<dd><p>Mainly for backwards compatibility to the Numeric C-API and for
simple casts to non-flexible types. Return a new array object with
the elements of <em>arr</em> cast to the data-type <em>typenum</em> which must
be one of the enumerated types and not a flexible type.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_CastToType">
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>* <code class="sig-name descname">PyArray_CastToType</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> arr</em>, <a class="reference internal" href="types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>*<em> type</em>, int<em> fortran</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_CastToType" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a new array of the <em>type</em> specified, casting the elements
of <em>arr</em> as appropriate. The fortran argument specifies the
ordering of the output array.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_CastTo">
int <code class="sig-name descname">PyArray_CastTo</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> out</em>, <a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> in</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_CastTo" title="Permalink to this definition">¶</a></dt>
<dd><p>As of 1.6, this function simply calls <a class="reference internal" href="#c.PyArray_CopyInto" title="PyArray_CopyInto"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_CopyInto</span></code></a>,
which handles the casting.</p>
<p>Cast the elements of the array <em>in</em> into the array <em>out</em>. The
output array should be writeable, have an integer-multiple of the
number of elements in the input array (more than one copy can be
placed in out), and have a data type that is one of the builtin
types.  Returns 0 on success and -1 if an error occurs.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_GetCastFunc">
PyArray_VectorUnaryFunc* <code class="sig-name descname">PyArray_GetCastFunc</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>*<em> from</em>, int<em> totype</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_GetCastFunc" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the low-level casting function to cast from the given
descriptor to the builtin type number. If no casting function
exists return <code class="docutils literal notranslate"><span class="pre">NULL</span></code> and set an error. Using this function
instead of direct access to <em>from</em> -&gt;f-&gt;cast will allow support of
any user-defined casting functions added to a descriptors casting
dictionary.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_CanCastSafely">
int <code class="sig-name descname">PyArray_CanCastSafely</code><span class="sig-paren">(</span>int<em> fromtype</em>, int<em> totype</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_CanCastSafely" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns non-zero if an array of data type <em>fromtype</em> can be cast
to an array of data type <em>totype</em> without losing information. An
exception is that 64-bit integers are allowed to be cast to 64-bit
floating point values even though this can lose precision on large
integers so as not to proliferate the use of long doubles without
explicit requests. Flexible array types are not checked according
to their lengths with this function.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_CanCastTo">
int <code class="sig-name descname">PyArray_CanCastTo</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>*<em> fromtype</em>, <a class="reference internal" href="types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>*<em> totype</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_CanCastTo" title="Permalink to this definition">¶</a></dt>
<dd><p><a class="reference internal" href="#c.PyArray_CanCastTypeTo" title="PyArray_CanCastTypeTo"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_CanCastTypeTo</span></code></a> supersedes this function in
NumPy 1.6 and later.</p>
<p>Equivalent to PyArray_CanCastTypeTo(fromtype, totype, NPY_SAFE_CASTING).</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_CanCastTypeTo">
int <code class="sig-name descname">PyArray_CanCastTypeTo</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>*<em> fromtype</em>, <a class="reference internal" href="types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>*<em> totype</em>, <a class="reference internal" href="#c.NPY_CASTING" title="NPY_CASTING">NPY_CASTING</a><em> casting</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_CanCastTypeTo" title="Permalink to this definition">¶</a></dt>
<dd><div class="versionadded">
<p><span class="versionmodified added">New in version 1.6.</span></p>
</div>
<p>Returns non-zero if an array of data type <em>fromtype</em> (which can
include flexible types) can be cast safely to an array of data
type <em>totype</em> (which can include flexible types) according to
the casting rule <em>casting</em>. For simple types with <a class="reference internal" href="#c.NPY_SAFE_CASTING" title="NPY_SAFE_CASTING"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_SAFE_CASTING</span></code></a>,
this is basically a wrapper around <a class="reference internal" href="#c.PyArray_CanCastSafely" title="PyArray_CanCastSafely"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_CanCastSafely</span></code></a>, but
for flexible types such as strings or unicode, it produces results
taking into account their sizes. Integer and float types can only be cast
to a string or unicode type using <a class="reference internal" href="#c.NPY_SAFE_CASTING" title="NPY_SAFE_CASTING"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_SAFE_CASTING</span></code></a> if the string
or unicode type is big enough to hold the max value of the integer/float
type being cast from.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_CanCastArrayTo">
int <code class="sig-name descname">PyArray_CanCastArrayTo</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> arr</em>, <a class="reference internal" href="types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>*<em> totype</em>, <a class="reference internal" href="#c.NPY_CASTING" title="NPY_CASTING">NPY_CASTING</a><em> casting</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_CanCastArrayTo" title="Permalink to this definition">¶</a></dt>
<dd><div class="versionadded">
<p><span class="versionmodified added">New in version 1.6.</span></p>
</div>
<p>Returns non-zero if <em>arr</em> can be cast to <em>totype</em> according
to the casting rule given in <em>casting</em>.  If <em>arr</em> is an array
scalar, its value is taken into account, and non-zero is also
returned when the value will not overflow or be truncated to
an integer when converting to a smaller type.</p>
<p>This is almost the same as the result of
PyArray_CanCastTypeTo(PyArray_MinScalarType(arr), totype, casting),
but it also handles a special case arising because the set
of uint values is not a subset of the int values for types with the
same number of bits.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_MinScalarType">
<a class="reference internal" href="types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>* <code class="sig-name descname">PyArray_MinScalarType</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> arr</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_MinScalarType" title="Permalink to this definition">¶</a></dt>
<dd><div class="versionadded">
<p><span class="versionmodified added">New in version 1.6.</span></p>
</div>
<p>If <em>arr</em> is an array, returns its data type descriptor, but if
<em>arr</em> is an array scalar (has 0 dimensions), it finds the data type
of smallest size to which the value may be converted
without overflow or truncation to an integer.</p>
<p>This function will not demote complex to float or anything to
boolean, but will demote a signed integer to an unsigned integer
when the scalar value is positive.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_PromoteTypes">
<a class="reference internal" href="types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>* <code class="sig-name descname">PyArray_PromoteTypes</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>*<em> type1</em>, <a class="reference internal" href="types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>*<em> type2</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_PromoteTypes" title="Permalink to this definition">¶</a></dt>
<dd><div class="versionadded">
<p><span class="versionmodified added">New in version 1.6.</span></p>
</div>
<p>Finds the data type of smallest size and kind to which <em>type1</em> and
<em>type2</em> may be safely converted. This function is symmetric and
associative. A string or unicode result will be the proper size for
storing the max value of the input types converted to a string or unicode.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_ResultType">
<a class="reference internal" href="types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>* <code class="sig-name descname">PyArray_ResultType</code><span class="sig-paren">(</span><a class="reference internal" href="dtype.html#c.npy_intp" title="npy_intp">npy_intp</a><em> narrs</em>, <a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>**arrs, <a class="reference internal" href="dtype.html#c.npy_intp" title="npy_intp">npy_intp</a><em> ndtypes</em>, <a class="reference internal" href="types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>**dtypes<span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_ResultType" title="Permalink to this definition">¶</a></dt>
<dd><div class="versionadded">
<p><span class="versionmodified added">New in version 1.6.</span></p>
</div>
<p>This applies type promotion to all the inputs,
using the NumPy rules for combining scalars and arrays, to
determine the output type of a set of operands.  This is the
same result type that ufuncs produce. The specific algorithm
used is as follows.</p>
<p>Categories are determined by first checking which of boolean,
integer (int/uint), or floating point (float/complex) the maximum
kind of all the arrays and the scalars are.</p>
<p>If there are only scalars or the maximum category of the scalars
is higher than the maximum category of the arrays,
the data types are combined with <a class="reference internal" href="#c.PyArray_PromoteTypes" title="PyArray_PromoteTypes"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_PromoteTypes</span></code></a>
to produce the return value.</p>
<p>Otherwise, PyArray_MinScalarType is called on each array, and
the resulting data types are all combined with
<a class="reference internal" href="#c.PyArray_PromoteTypes" title="PyArray_PromoteTypes"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_PromoteTypes</span></code></a> to produce the return value.</p>
<p>The set of int values is not a subset of the uint values for types
with the same number of bits, something not reflected in
<a class="reference internal" href="#c.PyArray_MinScalarType" title="PyArray_MinScalarType"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_MinScalarType</span></code></a>, but handled as a special case in
PyArray_ResultType.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_ObjectType">
int <code class="sig-name descname">PyArray_ObjectType</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> op</em>, int<em> mintype</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_ObjectType" title="Permalink to this definition">¶</a></dt>
<dd><p>This function is superceded by <a class="reference internal" href="#c.PyArray_MinScalarType" title="PyArray_MinScalarType"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_MinScalarType</span></code></a> and/or
<a class="reference internal" href="#c.PyArray_ResultType" title="PyArray_ResultType"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_ResultType</span></code></a>.</p>
<p>This function is useful for determining a common type that two or
more arrays can be converted to. It only works for non-flexible
array types as no itemsize information is passed. The <em>mintype</em>
argument represents the minimum type acceptable, and <em>op</em>
represents the object that will be converted to an array. The
return value is the enumerated typenumber that represents the
data-type that <em>op</em> should have.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_ArrayType">
void <code class="sig-name descname">PyArray_ArrayType</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> op</em>, <a class="reference internal" href="types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>*<em> mintype</em>, <a class="reference internal" href="types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>*<em> outtype</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_ArrayType" title="Permalink to this definition">¶</a></dt>
<dd><p>This function is superceded by <a class="reference internal" href="#c.PyArray_ResultType" title="PyArray_ResultType"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_ResultType</span></code></a>.</p>
<p>This function works similarly to <a class="reference internal" href="#c.PyArray_ObjectType" title="PyArray_ObjectType"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_ObjectType</span></code></a> (…)
except it handles flexible arrays. The <em>mintype</em> argument can have
an itemsize member and the <em>outtype</em> argument will have an
itemsize member at least as big but perhaps bigger depending on
the object <em>op</em>.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_ConvertToCommonType">
<a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>** <code class="sig-name descname">PyArray_ConvertToCommonType</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> op</em>, int*<em> n</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_ConvertToCommonType" title="Permalink to this definition">¶</a></dt>
<dd><p>The functionality this provides is largely superceded by iterator
<a class="reference internal" href="iterator.html#c.NpyIter" title="NpyIter"><code class="xref c c-type docutils literal notranslate"><span class="pre">NpyIter</span></code></a> introduced in 1.6, with flag
<a class="reference internal" href="iterator.html#c.NPY_ITER_COMMON_DTYPE" title="NPY_ITER_COMMON_DTYPE"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ITER_COMMON_DTYPE</span></code></a> or with the same dtype parameter for
all operands.</p>
<p>Convert a sequence of Python objects contained in <em>op</em> to an array
of ndarrays each having the same data type. The type is selected
based on the typenumber (larger type number is chosen over a
smaller one) ignoring objects that are only scalars. The length of
the sequence is returned in <em>n</em>, and an <em>n</em> -length array of
<a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyArrayObject</span></code></a> pointers is the return value (or <code class="docutils literal notranslate"><span class="pre">NULL</span></code> if an
error occurs). The returned array must be freed by the caller of
this routine (using <a class="reference internal" href="#c.PyDataMem_FREE" title="PyDataMem_FREE"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyDataMem_FREE</span></code></a> ) and all the array objects
in it <code class="docutils literal notranslate"><span class="pre">DECREF</span></code> ‘d or a memory-leak will occur. The example
template-code below shows a typically usage:</p>
<div class="highlight-c notranslate"><div class="highlight"><pre><span></span><span class="n">mps</span> <span class="o">=</span> <span class="n">PyArray_ConvertToCommonType</span><span class="p">(</span><span class="n">obj</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">n</span><span class="p">);</span>
<span class="k">if</span> <span class="p">(</span><span class="n">mps</span><span class="o">==</span><span class="nb">NULL</span><span class="p">)</span> <span class="k">return</span> <span class="nb">NULL</span><span class="p">;</span>
<span class="p">{</span><span class="n">code</span><span class="p">}</span>
<span class="o">&lt;</span><span class="n">before</span> <span class="k">return</span><span class="o">&gt;</span>
<span class="k">for</span> <span class="p">(</span><span class="n">i</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span> <span class="n">i</span><span class="o">&lt;</span><span class="n">n</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="n">Py_DECREF</span><span class="p">(</span><span class="n">mps</span><span class="p">[</span><span class="n">i</span><span class="p">]);</span>
<span class="n">PyDataMem_FREE</span><span class="p">(</span><span class="n">mps</span><span class="p">);</span>
<span class="p">{</span><span class="k">return</span><span class="p">}</span>
</pre></div>
</div>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_Zero">
char* <code class="sig-name descname">PyArray_Zero</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> arr</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_Zero" title="Permalink to this definition">¶</a></dt>
<dd><p>A pointer to newly created memory of size <em>arr</em> -&gt;itemsize that
holds the representation of 0 for that type. The returned pointer,
<em>ret</em>, <strong>must be freed</strong> using <a class="reference internal" href="#c.PyDataMem_FREE" title="PyDataMem_FREE"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyDataMem_FREE</span></code></a> (ret) when it is
not needed anymore.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_One">
char* <code class="sig-name descname">PyArray_One</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> arr</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_One" title="Permalink to this definition">¶</a></dt>
<dd><p>A pointer to newly created memory of size <em>arr</em> -&gt;itemsize that
holds the representation of 1 for that type. The returned pointer,
<em>ret</em>, <strong>must be freed</strong> using <a class="reference internal" href="#c.PyDataMem_FREE" title="PyDataMem_FREE"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyDataMem_FREE</span></code></a> (ret) when it
is not needed anymore.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_ValidType">
int <code class="sig-name descname">PyArray_ValidType</code><span class="sig-paren">(</span>int<em> typenum</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_ValidType" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns <a class="reference internal" href="#c.NPY_TRUE" title="NPY_TRUE"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_TRUE</span></code></a> if <em>typenum</em> represents a valid type-number
(builtin or user-defined or character code). Otherwise, this
function returns <a class="reference internal" href="#c.NPY_FALSE" title="NPY_FALSE"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_FALSE</span></code></a>.</p>
</dd></dl>

</div>
<div class="section" id="new-data-types">
<h3>New data types<a class="headerlink" href="#new-data-types" title="Permalink to this headline">¶</a></h3>
<dl class="function">
<dt id="c.PyArray_InitArrFuncs">
void <code class="sig-name descname">PyArray_InitArrFuncs</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArray_ArrFuncs" title="PyArray_ArrFuncs">PyArray_ArrFuncs</a>*<em> f</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_InitArrFuncs" title="Permalink to this definition">¶</a></dt>
<dd><p>Initialize all function pointers and members to <code class="docutils literal notranslate"><span class="pre">NULL</span></code>.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_RegisterDataType">
int <code class="sig-name descname">PyArray_RegisterDataType</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>*<em> dtype</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_RegisterDataType" title="Permalink to this definition">¶</a></dt>
<dd><p>Register a data-type as a new user-defined data type for
arrays. The type must have most of its entries filled in. This is
not always checked and errors can produce segfaults. In
particular, the typeobj member of the <code class="docutils literal notranslate"><span class="pre">dtype</span></code> structure must be
filled with a Python type that has a fixed-size element-size that
corresponds to the elsize member of <em>dtype</em>. Also the <code class="docutils literal notranslate"><span class="pre">f</span></code>
member must have the required functions: nonzero, copyswap,
copyswapn, getitem, setitem, and cast (some of the cast functions
may be <code class="docutils literal notranslate"><span class="pre">NULL</span></code> if no support is desired). To avoid confusion, you
should choose a unique character typecode but this is not enforced
and not relied on internally.</p>
<p>A user-defined type number is returned that uniquely identifies
the type. A pointer to the new structure can then be obtained from
<a class="reference internal" href="#c.PyArray_DescrFromType" title="PyArray_DescrFromType"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_DescrFromType</span></code></a> using the returned type number. A -1 is
returned if an error occurs.  If this <em>dtype</em> has already been
registered (checked only by the address of the pointer), then
return the previously-assigned type-number.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_RegisterCastFunc">
int <code class="sig-name descname">PyArray_RegisterCastFunc</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>*<em> descr</em>, int<em> totype</em>, PyArray_VectorUnaryFunc*<em> castfunc</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_RegisterCastFunc" title="Permalink to this definition">¶</a></dt>
<dd><p>Register a low-level casting function, <em>castfunc</em>, to convert
from the data-type, <em>descr</em>, to the given data-type number,
<em>totype</em>. Any old casting function is over-written. A <code class="docutils literal notranslate"><span class="pre">0</span></code> is
returned on success or a <code class="docutils literal notranslate"><span class="pre">-1</span></code> on failure.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_RegisterCanCast">
int <code class="sig-name descname">PyArray_RegisterCanCast</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>*<em> descr</em>, int<em> totype</em>, <a class="reference internal" href="#c.NPY_SCALARKIND" title="NPY_SCALARKIND">NPY_SCALARKIND</a><em> scalar</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_RegisterCanCast" title="Permalink to this definition">¶</a></dt>
<dd><p>Register the data-type number, <em>totype</em>, as castable from
data-type object, <em>descr</em>, of the given <em>scalar</em> kind. Use
<em>scalar</em> = <a class="reference internal" href="#c.NPY_NOSCALAR" title="NPY_NOSCALAR"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_NOSCALAR</span></code></a> to register that an array of data-type
<em>descr</em> can be cast safely to a data-type whose type_number is
<em>totype</em>.</p>
</dd></dl>

</div>
<div class="section" id="special-functions-for-npy-object">
<h3>Special functions for NPY_OBJECT<a class="headerlink" href="#special-functions-for-npy-object" title="Permalink to this headline">¶</a></h3>
<dl class="function">
<dt id="c.PyArray_INCREF">
int <code class="sig-name descname">PyArray_INCREF</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> op</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_INCREF" title="Permalink to this definition">¶</a></dt>
<dd><p>Used for an array, <em>op</em>, that contains any Python objects. It
increments the reference count of every object in the array
according to the data-type of <em>op</em>. A -1 is returned if an error
occurs, otherwise 0 is returned.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_Item_INCREF">
void <code class="sig-name descname">PyArray_Item_INCREF</code><span class="sig-paren">(</span>char*<em> ptr</em>, <a class="reference internal" href="types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>*<em> dtype</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_Item_INCREF" title="Permalink to this definition">¶</a></dt>
<dd><p>A function to INCREF all the objects at the location <em>ptr</em>
according to the data-type <em>dtype</em>. If <em>ptr</em> is the start of a
structured type with an object at any offset, then this will (recursively)
increment the reference count of all object-like items in the
structured type.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_XDECREF">
int <code class="sig-name descname">PyArray_XDECREF</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> op</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_XDECREF" title="Permalink to this definition">¶</a></dt>
<dd><p>Used for an array, <em>op</em>, that contains any Python objects. It
decrements the reference count of every object in the array
according to the data-type of <em>op</em>. Normal return value is 0. A
-1 is returned if an error occurs.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_Item_XDECREF">
void <code class="sig-name descname">PyArray_Item_XDECREF</code><span class="sig-paren">(</span>char*<em> ptr</em>, <a class="reference internal" href="types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>*<em> dtype</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_Item_XDECREF" title="Permalink to this definition">¶</a></dt>
<dd><p>A function to XDECREF all the object-like items at the location
<em>ptr</em> as recorded in the data-type, <em>dtype</em>. This works
recursively so that if <code class="docutils literal notranslate"><span class="pre">dtype</span></code> itself has fields with data-types
that contain object-like items, all the object-like fields will be
XDECREF <code class="docutils literal notranslate"><span class="pre">'d</span></code>.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_FillObjectArray">
void <code class="sig-name descname">PyArray_FillObjectArray</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> arr</em>, <a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> obj</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_FillObjectArray" title="Permalink to this definition">¶</a></dt>
<dd><p>Fill a newly created array with a single value obj at all
locations in the structure with object data-types. No checking is
performed but <em>arr</em> must be of data-type <a class="reference internal" href="dtype.html#c.NPY_OBJECT" title="NPY_OBJECT"><code class="xref c c-type docutils literal notranslate"><span class="pre">NPY_OBJECT</span></code></a> and be
single-segment and uninitialized (no previous objects in
position). Use <code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_DECREF</span></code> (<em>arr</em>) if you need to
decrement all the items in the object array prior to calling this
function.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_SetUpdateIfCopyBase">
int <code class="sig-name descname">PyArray_SetUpdateIfCopyBase</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> arr</em>, <a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> base</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_SetUpdateIfCopyBase" title="Permalink to this definition">¶</a></dt>
<dd><p>Precondition: <code class="docutils literal notranslate"><span class="pre">arr</span></code> is a copy of <code class="docutils literal notranslate"><span class="pre">base</span></code> (though possibly with different
strides, ordering, etc.) Set the UPDATEIFCOPY flag and <code class="docutils literal notranslate"><span class="pre">arr-&gt;base</span></code> so
that when <code class="docutils literal notranslate"><span class="pre">arr</span></code> is destructed, it will copy any changes back to <code class="docutils literal notranslate"><span class="pre">base</span></code>.
DEPRECATED, use <code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_SetWritebackIfCopyBase`</span></code>.</p>
<p>Returns 0 for success, -1 for failure.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_SetWritebackIfCopyBase">
int <code class="sig-name descname">PyArray_SetWritebackIfCopyBase</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> arr</em>, <a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> base</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_SetWritebackIfCopyBase" title="Permalink to this definition">¶</a></dt>
<dd><p>Precondition: <code class="docutils literal notranslate"><span class="pre">arr</span></code> is a copy of <code class="docutils literal notranslate"><span class="pre">base</span></code> (though possibly with different
strides, ordering, etc.) Sets the <a class="reference internal" href="#c.NPY_ARRAY_WRITEBACKIFCOPY" title="NPY_ARRAY_WRITEBACKIFCOPY"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_WRITEBACKIFCOPY</span></code></a> flag
and <code class="docutils literal notranslate"><span class="pre">arr-&gt;base</span></code>, and set <code class="docutils literal notranslate"><span class="pre">base</span></code> to READONLY. Call
<a class="reference internal" href="#c.PyArray_ResolveWritebackIfCopy" title="PyArray_ResolveWritebackIfCopy"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_ResolveWritebackIfCopy</span></code></a> before calling
<em class="xref py py-obj">Py_DECREF`</em> in order copy any changes back to <code class="docutils literal notranslate"><span class="pre">base</span></code> and
reset the READONLY flag.</p>
<p>Returns 0 for success, -1 for failure.</p>
</dd></dl>

</div>
</div>
<div class="section" id="array-flags">
<span id="id1"></span><h2>Array flags<a class="headerlink" href="#array-flags" title="Permalink to this headline">¶</a></h2>
<p>The <code class="docutils literal notranslate"><span class="pre">flags</span></code> attribute of the <code class="docutils literal notranslate"><span class="pre">PyArrayObject</span></code> structure contains
important information about the memory used by the array (pointed to
by the data member) This flag information must be kept accurate or
strange results and even segfaults may result.</p>
<p>There are 6 (binary) flags that describe the memory area used by the
data buffer.  These constants are defined in <code class="docutils literal notranslate"><span class="pre">arrayobject.h</span></code> and
determine the bit-position of the flag.  Python exposes a nice
attribute- based interface as well as a dictionary-like interface for
getting (and, if appropriate, setting) these flags.</p>
<p>Memory areas of all kinds can be pointed to by an ndarray, necessitating
these flags.  If you get an arbitrary <code class="docutils literal notranslate"><span class="pre">PyArrayObject</span></code> in C-code, you
need to be aware of the flags that are set.  If you need to guarantee
a certain kind of array (like <a class="reference internal" href="#c.NPY_ARRAY_C_CONTIGUOUS" title="NPY_ARRAY_C_CONTIGUOUS"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_C_CONTIGUOUS</span></code></a> and
<a class="reference internal" href="#c.NPY_ARRAY_BEHAVED" title="NPY_ARRAY_BEHAVED"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_BEHAVED</span></code></a>), then pass these requirements into the
PyArray_FromAny function.</p>
<div class="section" id="basic-array-flags">
<h3>Basic Array Flags<a class="headerlink" href="#basic-array-flags" title="Permalink to this headline">¶</a></h3>
<p>An ndarray can have a data segment that is not a simple contiguous
chunk of well-behaved memory you can manipulate. It may not be aligned
with word boundaries (very important on some platforms). It might have
its data in a different byte-order than the machine recognizes. It
might not be writeable. It might be in Fortan-contiguous order. The
array flags are used to indicate what can be said about data
associated with an array.</p>
<p>In versions 1.6 and earlier of NumPy, the following flags
did not have the _ARRAY_ macro namespace in them. That form
of the constant names is deprecated in 1.7.</p>
<dl class="var">
<dt>
<code class="sig-name descname">NPY_ARRAY_C_CONTIGUOUS</code></dt>
<dd><p>The data area is in C-style contiguous order (last index varies the
fastest).</p>
</dd></dl>

<dl class="var">
<dt>
<code class="sig-name descname">NPY_ARRAY_F_CONTIGUOUS</code></dt>
<dd><p>The data area is in Fortran-style contiguous order (first index varies
the fastest).</p>
</dd></dl>

<div class="admonition note">
<p class="admonition-title">Note</p>
<p>Arrays can be both C-style and Fortran-style contiguous simultaneously.
This is clear for 1-dimensional arrays, but can also be true for higher
dimensional arrays.</p>
<p>Even for contiguous arrays a stride for a given dimension
<code class="docutils literal notranslate"><span class="pre">arr.strides[dim]</span></code> may be <em>arbitrary</em> if <code class="docutils literal notranslate"><span class="pre">arr.shape[dim]</span> <span class="pre">==</span> <span class="pre">1</span></code>
or the array has no elements.
It does <em>not</em> generally hold that <code class="docutils literal notranslate"><span class="pre">self.strides[-1]</span> <span class="pre">==</span> <span class="pre">self.itemsize</span></code>
for C-style contiguous arrays or <code class="docutils literal notranslate"><span class="pre">self.strides[0]</span> <span class="pre">==</span> <span class="pre">self.itemsize</span></code> for
Fortran-style contiguous arrays is true. The correct way to access the
<code class="docutils literal notranslate"><span class="pre">itemsize</span></code> of an array from the C API is <code class="docutils literal notranslate"><span class="pre">PyArray_ITEMSIZE(arr)</span></code>.</p>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="../arrays.ndarray.html#arrays-ndarray"><span class="std std-ref">Internal memory layout of an ndarray</span></a></p>
</div>
</div>
<dl class="var">
<dt id="c.NPY_ARRAY_OWNDATA">
<code class="sig-name descname">NPY_ARRAY_OWNDATA</code><a class="headerlink" href="#c.NPY_ARRAY_OWNDATA" title="Permalink to this definition">¶</a></dt>
<dd><p>The data area is owned by this array.</p>
</dd></dl>

<dl class="var">
<dt>
<code class="sig-name descname">NPY_ARRAY_ALIGNED</code></dt>
<dd><p>The data area and all array elements are aligned appropriately.</p>
</dd></dl>

<dl class="var">
<dt>
<code class="sig-name descname">NPY_ARRAY_WRITEABLE</code></dt>
<dd><p>The data area can be written to.</p>
<p>Notice that the above 3 flags are defined so that a new, well-
behaved array has these flags defined as true.</p>
</dd></dl>

<dl class="var">
<dt>
<code class="sig-name descname">NPY_ARRAY_WRITEBACKIFCOPY</code></dt>
<dd><p>The data area represents a (well-behaved) copy whose information
should be transferred back to the original when
<a class="reference internal" href="#c.PyArray_ResolveWritebackIfCopy" title="PyArray_ResolveWritebackIfCopy"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_ResolveWritebackIfCopy</span></code></a> is called.</p>
<p>This is a special flag that is set if this array represents a copy
made because a user required certain flags in
<a class="reference internal" href="#c.PyArray_FromAny" title="PyArray_FromAny"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_FromAny</span></code></a> and a copy had to be made of some other
array (and the user asked for this flag to be set in such a
situation). The base attribute then points to the “misbehaved”
array (which is set read_only). :c:func`PyArray_ResolveWritebackIfCopy`
will copy its contents back to the “misbehaved”
array (casting if necessary) and will reset the “misbehaved” array
to <a class="reference internal" href="#c.NPY_ARRAY_WRITEABLE" title="NPY_ARRAY_WRITEABLE"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_WRITEABLE</span></code></a>. If the “misbehaved” array was not
<a class="reference internal" href="#c.NPY_ARRAY_WRITEABLE" title="NPY_ARRAY_WRITEABLE"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_WRITEABLE</span></code></a> to begin with then <a class="reference internal" href="#c.PyArray_FromAny" title="PyArray_FromAny"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_FromAny</span></code></a>
would have returned an error because <a class="reference internal" href="#c.NPY_ARRAY_WRITEBACKIFCOPY" title="NPY_ARRAY_WRITEBACKIFCOPY"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_WRITEBACKIFCOPY</span></code></a>
would not have been possible.</p>
</dd></dl>

<dl class="var">
<dt>
<code class="sig-name descname">NPY_ARRAY_UPDATEIFCOPY</code></dt>
<dd><p>A deprecated version of <a class="reference internal" href="#c.NPY_ARRAY_WRITEBACKIFCOPY" title="NPY_ARRAY_WRITEBACKIFCOPY"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_WRITEBACKIFCOPY</span></code></a> which
depends upon <code class="docutils literal notranslate"><span class="pre">dealloc</span></code> to trigger the writeback. For backwards
compatibility, <a class="reference internal" href="#c.PyArray_ResolveWritebackIfCopy" title="PyArray_ResolveWritebackIfCopy"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_ResolveWritebackIfCopy</span></code></a> is called at
<code class="docutils literal notranslate"><span class="pre">dealloc</span></code> but relying
on that behavior is deprecated and not supported in PyPy.</p>
</dd></dl>

<p><a class="reference internal" href="#c.PyArray_UpdateFlags" title="PyArray_UpdateFlags"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_UpdateFlags</span></code></a> (obj, flags) will update the <code class="docutils literal notranslate"><span class="pre">obj-&gt;flags</span></code>
for <code class="docutils literal notranslate"><span class="pre">flags</span></code> which can be any of <a class="reference internal" href="#c.NPY_ARRAY_C_CONTIGUOUS" title="NPY_ARRAY_C_CONTIGUOUS"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_C_CONTIGUOUS</span></code></a>,
<a class="reference internal" href="#c.NPY_ARRAY_F_CONTIGUOUS" title="NPY_ARRAY_F_CONTIGUOUS"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_F_CONTIGUOUS</span></code></a>, <a class="reference internal" href="#c.NPY_ARRAY_ALIGNED" title="NPY_ARRAY_ALIGNED"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_ALIGNED</span></code></a>, or
<a class="reference internal" href="#c.NPY_ARRAY_WRITEABLE" title="NPY_ARRAY_WRITEABLE"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_WRITEABLE</span></code></a>.</p>
</div>
<div class="section" id="combinations-of-array-flags">
<h3>Combinations of array flags<a class="headerlink" href="#combinations-of-array-flags" title="Permalink to this headline">¶</a></h3>
<dl class="var">
<dt>
<code class="sig-name descname">NPY_ARRAY_BEHAVED</code></dt>
<dd><p><a class="reference internal" href="#c.NPY_ARRAY_ALIGNED" title="NPY_ARRAY_ALIGNED"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_ALIGNED</span></code></a> | <a class="reference internal" href="#c.NPY_ARRAY_WRITEABLE" title="NPY_ARRAY_WRITEABLE"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_WRITEABLE</span></code></a></p>
</dd></dl>

<dl class="var">
<dt>
<code class="sig-name descname">NPY_ARRAY_CARRAY</code></dt>
<dd><p><a class="reference internal" href="#c.NPY_ARRAY_C_CONTIGUOUS" title="NPY_ARRAY_C_CONTIGUOUS"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_C_CONTIGUOUS</span></code></a> | <a class="reference internal" href="#c.NPY_ARRAY_BEHAVED" title="NPY_ARRAY_BEHAVED"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_BEHAVED</span></code></a></p>
</dd></dl>

<dl class="var">
<dt>
<code class="sig-name descname">NPY_ARRAY_CARRAY_RO</code></dt>
<dd><p><a class="reference internal" href="#c.NPY_ARRAY_C_CONTIGUOUS" title="NPY_ARRAY_C_CONTIGUOUS"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_C_CONTIGUOUS</span></code></a> | <a class="reference internal" href="#c.NPY_ARRAY_ALIGNED" title="NPY_ARRAY_ALIGNED"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_ALIGNED</span></code></a></p>
</dd></dl>

<dl class="var">
<dt>
<code class="sig-name descname">NPY_ARRAY_FARRAY</code></dt>
<dd><p><a class="reference internal" href="#c.NPY_ARRAY_F_CONTIGUOUS" title="NPY_ARRAY_F_CONTIGUOUS"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_F_CONTIGUOUS</span></code></a> | <a class="reference internal" href="#c.NPY_ARRAY_BEHAVED" title="NPY_ARRAY_BEHAVED"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_BEHAVED</span></code></a></p>
</dd></dl>

<dl class="var">
<dt>
<code class="sig-name descname">NPY_ARRAY_FARRAY_RO</code></dt>
<dd><p><a class="reference internal" href="#c.NPY_ARRAY_F_CONTIGUOUS" title="NPY_ARRAY_F_CONTIGUOUS"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_F_CONTIGUOUS</span></code></a> | <a class="reference internal" href="#c.NPY_ARRAY_ALIGNED" title="NPY_ARRAY_ALIGNED"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_ALIGNED</span></code></a></p>
</dd></dl>

<dl class="var">
<dt>
<code class="sig-name descname">NPY_ARRAY_DEFAULT</code></dt>
<dd><p><a class="reference internal" href="#c.NPY_ARRAY_CARRAY" title="NPY_ARRAY_CARRAY"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_CARRAY</span></code></a></p>
</dd></dl>

<dl class="var">
<dt id="c.NPY_ARRAY_UPDATE_ALL">
<code class="sig-name descname">NPY_ARRAY_UPDATE_ALL</code><a class="headerlink" href="#c.NPY_ARRAY_UPDATE_ALL" title="Permalink to this definition">¶</a></dt>
<dd><p><a class="reference internal" href="#c.NPY_ARRAY_C_CONTIGUOUS" title="NPY_ARRAY_C_CONTIGUOUS"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_C_CONTIGUOUS</span></code></a> | <a class="reference internal" href="#c.NPY_ARRAY_F_CONTIGUOUS" title="NPY_ARRAY_F_CONTIGUOUS"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_F_CONTIGUOUS</span></code></a> | <a class="reference internal" href="#c.NPY_ARRAY_ALIGNED" title="NPY_ARRAY_ALIGNED"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_ALIGNED</span></code></a></p>
</dd></dl>

</div>
<div class="section" id="flag-like-constants">
<h3>Flag-like constants<a class="headerlink" href="#flag-like-constants" title="Permalink to this headline">¶</a></h3>
<p>These constants are used in <a class="reference internal" href="#c.PyArray_FromAny" title="PyArray_FromAny"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_FromAny</span></code></a> (and its macro forms) to
specify desired properties of the new array.</p>
<dl class="var">
<dt>
<code class="sig-name descname">NPY_ARRAY_FORCECAST</code></dt>
<dd><p>Cast to the desired type, even if it can’t be done without losing
information.</p>
</dd></dl>

<dl class="var">
<dt>
<code class="sig-name descname">NPY_ARRAY_ENSURECOPY</code></dt>
<dd><p>Make sure the resulting array is a copy of the original.</p>
</dd></dl>

<dl class="var">
<dt>
<code class="sig-name descname">NPY_ARRAY_ENSUREARRAY</code></dt>
<dd><p>Make sure the resulting object is an actual ndarray, and not a sub-class.</p>
</dd></dl>

<dl class="var">
<dt>
<code class="sig-name descname">NPY_ARRAY_NOTSWAPPED</code></dt>
<dd><p>Only used in <a class="reference internal" href="#c.PyArray_CheckFromAny" title="PyArray_CheckFromAny"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_CheckFromAny</span></code></a> to over-ride the byteorder
of the data-type object passed in.</p>
</dd></dl>

<dl class="var">
<dt>
<code class="sig-name descname">NPY_ARRAY_BEHAVED_NS</code></dt>
<dd><p><a class="reference internal" href="#c.NPY_ARRAY_ALIGNED" title="NPY_ARRAY_ALIGNED"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_ALIGNED</span></code></a> | <a class="reference internal" href="#c.NPY_ARRAY_WRITEABLE" title="NPY_ARRAY_WRITEABLE"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_WRITEABLE</span></code></a> | <a class="reference internal" href="#c.NPY_ARRAY_NOTSWAPPED" title="NPY_ARRAY_NOTSWAPPED"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_NOTSWAPPED</span></code></a></p>
</dd></dl>

</div>
<div class="section" id="flag-checking">
<h3>Flag checking<a class="headerlink" href="#flag-checking" title="Permalink to this headline">¶</a></h3>
<p>For all of these macros <em>arr</em> must be an instance of a (subclass of)
<a class="reference internal" href="types-and-structures.html#c.PyArray_Type" title="PyArray_Type"><code class="xref c c-data docutils literal notranslate"><span class="pre">PyArray_Type</span></code></a>.</p>
<dl class="function">
<dt id="c.PyArray_CHKFLAGS">
<code class="sig-name descname">PyArray_CHKFLAGS</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a><em> *arr</em>, flags<span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_CHKFLAGS" title="Permalink to this definition">¶</a></dt>
<dd><p>The first parameter, arr, must be an ndarray or subclass. The
parameter, <em>flags</em>, should be an integer consisting of bitwise
combinations of the possible flags an array can have:
<a class="reference internal" href="#c.NPY_ARRAY_C_CONTIGUOUS" title="NPY_ARRAY_C_CONTIGUOUS"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_C_CONTIGUOUS</span></code></a>, <a class="reference internal" href="#c.NPY_ARRAY_F_CONTIGUOUS" title="NPY_ARRAY_F_CONTIGUOUS"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_F_CONTIGUOUS</span></code></a>,
<a class="reference internal" href="#c.NPY_ARRAY_OWNDATA" title="NPY_ARRAY_OWNDATA"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_OWNDATA</span></code></a>, <a class="reference internal" href="#c.NPY_ARRAY_ALIGNED" title="NPY_ARRAY_ALIGNED"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_ALIGNED</span></code></a>,
<a class="reference internal" href="#c.NPY_ARRAY_WRITEABLE" title="NPY_ARRAY_WRITEABLE"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_WRITEABLE</span></code></a>, <a class="reference internal" href="#c.NPY_ARRAY_WRITEBACKIFCOPY" title="NPY_ARRAY_WRITEBACKIFCOPY"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_WRITEBACKIFCOPY</span></code></a>,
<a class="reference internal" href="#c.NPY_ARRAY_UPDATEIFCOPY" title="NPY_ARRAY_UPDATEIFCOPY"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_UPDATEIFCOPY</span></code></a>.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_IS_C_CONTIGUOUS">
<code class="sig-name descname">PyArray_IS_C_CONTIGUOUS</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a><em> *arr</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_IS_C_CONTIGUOUS" title="Permalink to this definition">¶</a></dt>
<dd><p>Evaluates true if <em>arr</em> is C-style contiguous.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_IS_F_CONTIGUOUS">
<code class="sig-name descname">PyArray_IS_F_CONTIGUOUS</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a><em> *arr</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_IS_F_CONTIGUOUS" title="Permalink to this definition">¶</a></dt>
<dd><p>Evaluates true if <em>arr</em> is Fortran-style contiguous.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_ISFORTRAN">
<code class="sig-name descname">PyArray_ISFORTRAN</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a><em> *arr</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_ISFORTRAN" title="Permalink to this definition">¶</a></dt>
<dd><p>Evaluates true if <em>arr</em> is Fortran-style contiguous and <em>not</em>
C-style contiguous. <a class="reference internal" href="#c.PyArray_IS_F_CONTIGUOUS" title="PyArray_IS_F_CONTIGUOUS"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_IS_F_CONTIGUOUS</span></code></a>
is the correct way to test for Fortran-style contiguity.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_ISWRITEABLE">
<code class="sig-name descname">PyArray_ISWRITEABLE</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a><em> *arr</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_ISWRITEABLE" title="Permalink to this definition">¶</a></dt>
<dd><p>Evaluates true if the data area of <em>arr</em> can be written to</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_ISALIGNED">
<code class="sig-name descname">PyArray_ISALIGNED</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a><em> *arr</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_ISALIGNED" title="Permalink to this definition">¶</a></dt>
<dd><p>Evaluates true if the data area of <em>arr</em> is properly aligned on
the machine.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_ISBEHAVED">
<code class="sig-name descname">PyArray_ISBEHAVED</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a><em> *arr</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_ISBEHAVED" title="Permalink to this definition">¶</a></dt>
<dd><p>Evaluates true if the data area of <em>arr</em> is aligned and writeable
and in machine byte-order according to its descriptor.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_ISBEHAVED_RO">
<code class="sig-name descname">PyArray_ISBEHAVED_RO</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a><em> *arr</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_ISBEHAVED_RO" title="Permalink to this definition">¶</a></dt>
<dd><p>Evaluates true if the data area of <em>arr</em> is aligned and in machine
byte-order.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_ISCARRAY">
<code class="sig-name descname">PyArray_ISCARRAY</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a><em> *arr</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_ISCARRAY" title="Permalink to this definition">¶</a></dt>
<dd><p>Evaluates true if the data area of <em>arr</em> is C-style contiguous,
and <a class="reference internal" href="#c.PyArray_ISBEHAVED" title="PyArray_ISBEHAVED"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_ISBEHAVED</span></code></a> (<em>arr</em>) is true.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_ISFARRAY">
<code class="sig-name descname">PyArray_ISFARRAY</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a><em> *arr</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_ISFARRAY" title="Permalink to this definition">¶</a></dt>
<dd><p>Evaluates true if the data area of <em>arr</em> is Fortran-style
contiguous and <a class="reference internal" href="#c.PyArray_ISBEHAVED" title="PyArray_ISBEHAVED"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_ISBEHAVED</span></code></a> (<em>arr</em>) is true.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_ISCARRAY_RO">
<code class="sig-name descname">PyArray_ISCARRAY_RO</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a><em> *arr</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_ISCARRAY_RO" title="Permalink to this definition">¶</a></dt>
<dd><p>Evaluates true if the data area of <em>arr</em> is C-style contiguous,
aligned, and in machine byte-order.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_ISFARRAY_RO">
<code class="sig-name descname">PyArray_ISFARRAY_RO</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a><em> *arr</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_ISFARRAY_RO" title="Permalink to this definition">¶</a></dt>
<dd><p>Evaluates true if the data area of <em>arr</em> is Fortran-style
contiguous, aligned, and in machine byte-order <strong>.</strong></p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_ISONESEGMENT">
<code class="sig-name descname">PyArray_ISONESEGMENT</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a><em> *arr</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_ISONESEGMENT" title="Permalink to this definition">¶</a></dt>
<dd><p>Evaluates true if the data area of <em>arr</em> consists of a single
(C-style or Fortran-style) contiguous segment.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_UpdateFlags">
void <code class="sig-name descname">PyArray_UpdateFlags</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> arr</em>, int<em> flagmask</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_UpdateFlags" title="Permalink to this definition">¶</a></dt>
<dd><p>The <a class="reference internal" href="#c.NPY_ARRAY_C_CONTIGUOUS" title="NPY_ARRAY_C_CONTIGUOUS"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_C_CONTIGUOUS</span></code></a>, <a class="reference internal" href="#c.NPY_ARRAY_ALIGNED" title="NPY_ARRAY_ALIGNED"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_ALIGNED</span></code></a>, and
<a class="reference internal" href="#c.NPY_ARRAY_F_CONTIGUOUS" title="NPY_ARRAY_F_CONTIGUOUS"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_F_CONTIGUOUS</span></code></a> array flags can be “calculated” from the
array object itself. This routine updates one or more of these
flags of <em>arr</em> as specified in <em>flagmask</em> by performing the
required calculation.</p>
</dd></dl>

<div class="admonition warning">
<p class="admonition-title">Warning</p>
<p>It is important to keep the flags updated (using
<a class="reference internal" href="#c.PyArray_UpdateFlags" title="PyArray_UpdateFlags"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_UpdateFlags</span></code></a> can help) whenever a manipulation with an
array is performed that might cause them to change. Later
calculations in NumPy that rely on the state of these flags do not
repeat the calculation to update them.</p>
</div>
</div>
</div>
<div class="section" id="array-method-alternative-api">
<h2>Array method alternative API<a class="headerlink" href="#array-method-alternative-api" title="Permalink to this headline">¶</a></h2>
<div class="section" id="conversion">
<h3>Conversion<a class="headerlink" href="#conversion" title="Permalink to this headline">¶</a></h3>
<dl class="function">
<dt id="c.PyArray_GetField">
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>* <code class="sig-name descname">PyArray_GetField</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> self</em>, <a class="reference internal" href="types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>*<em> dtype</em>, int<em> offset</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_GetField" title="Permalink to this definition">¶</a></dt>
<dd><p>Equivalent to <a class="reference internal" href="../generated/numpy.ndarray.getfield.html#numpy.ndarray.getfield" title="numpy.ndarray.getfield"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ndarray.getfield</span></code></a>
(<em>self</em>, <em>dtype</em>, <em>offset</em>). This function <a class="reference external" href="https://docs.python.org/3/c-api/intro.html?reference-count-details">steals a reference</a>
to <em class="xref py py-obj">PyArray_Descr</em> and returns a new array of the given <em class="xref py py-obj">dtype</em> using
the data in the current array at a specified <em class="xref py py-obj">offset</em> in bytes. The
<em class="xref py py-obj">offset</em> plus the itemsize of the new array type must be less than <code class="docutils literal notranslate"><span class="pre">self</span>
<span class="pre">-&gt;descr-&gt;elsize</span></code> or an error is raised. The same shape and strides
as the original array are used. Therefore, this function has the
effect of returning a field from a structured array. But, it can also
be used to select specific bytes or groups of bytes from any array
type.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_SetField">
int <code class="sig-name descname">PyArray_SetField</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> self</em>, <a class="reference internal" href="types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>*<em> dtype</em>, int<em> offset</em>, <a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> val</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_SetField" title="Permalink to this definition">¶</a></dt>
<dd><p>Equivalent to <a class="reference internal" href="../generated/numpy.ndarray.setfield.html#numpy.ndarray.setfield" title="numpy.ndarray.setfield"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ndarray.setfield</span></code></a> (<em>self</em>, <em>val</em>, <em>dtype</em>, <em>offset</em>
). Set the field starting at <em>offset</em> in bytes and of the given
<em>dtype</em> to <em>val</em>. The <em>offset</em> plus <em>dtype</em> -&gt;elsize must be less
than <em>self</em> -&gt;descr-&gt;elsize or an error is raised. Otherwise, the
<em>val</em> argument is converted to an array and copied into the field
pointed to. If necessary, the elements of <em>val</em> are repeated to
fill the destination array, But, the number of elements in the
destination must be an integer multiple of the number of elements
in <em>val</em>.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_Byteswap">
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>* <code class="sig-name descname">PyArray_Byteswap</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> self</em>, Bool<em> inplace</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_Byteswap" title="Permalink to this definition">¶</a></dt>
<dd><p>Equivalent to <a class="reference internal" href="../generated/numpy.ndarray.byteswap.html#numpy.ndarray.byteswap" title="numpy.ndarray.byteswap"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ndarray.byteswap</span></code></a> (<em>self</em>, <em>inplace</em>). Return an array
whose data area is byteswapped. If <em>inplace</em> is non-zero, then do
the byteswap inplace and return a reference to self. Otherwise,
create a byteswapped copy and leave self unchanged.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_NewCopy">
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>* <code class="sig-name descname">PyArray_NewCopy</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> old</em>, <a class="reference internal" href="#c.NPY_ORDER" title="NPY_ORDER">NPY_ORDER</a><em> order</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_NewCopy" title="Permalink to this definition">¶</a></dt>
<dd><p>Equivalent to <a class="reference internal" href="../generated/numpy.ndarray.copy.html#numpy.ndarray.copy" title="numpy.ndarray.copy"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ndarray.copy</span></code></a> (<em>self</em>, <em>fortran</em>). Make a copy of the
<em>old</em> array. The returned array is always aligned and writeable
with data interpreted the same as the old array. If <em>order</em> is
<a class="reference internal" href="#c.NPY_CORDER" title="NPY_CORDER"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_CORDER</span></code></a>, then a C-style contiguous array is returned. If
<em>order</em> is <a class="reference internal" href="#c.NPY_FORTRANORDER" title="NPY_FORTRANORDER"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_FORTRANORDER</span></code></a>, then a Fortran-style contiguous
array is returned. If <em>order is</em> <a class="reference internal" href="#c.NPY_ANYORDER" title="NPY_ANYORDER"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ANYORDER</span></code></a>, then the array
returned is Fortran-style contiguous only if the old one is;
otherwise, it is C-style contiguous.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_ToList">
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>* <code class="sig-name descname">PyArray_ToList</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> self</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_ToList" title="Permalink to this definition">¶</a></dt>
<dd><p>Equivalent to <a class="reference internal" href="../generated/numpy.ndarray.tolist.html#numpy.ndarray.tolist" title="numpy.ndarray.tolist"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ndarray.tolist</span></code></a> (<em>self</em>). Return a nested Python list
from <em>self</em>.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_ToString">
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>* <code class="sig-name descname">PyArray_ToString</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> self</em>, <a class="reference internal" href="#c.NPY_ORDER" title="NPY_ORDER">NPY_ORDER</a><em> order</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_ToString" title="Permalink to this definition">¶</a></dt>
<dd><p>Equivalent to <a class="reference internal" href="../generated/numpy.ndarray.tobytes.html#numpy.ndarray.tobytes" title="numpy.ndarray.tobytes"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ndarray.tobytes</span></code></a> (<em>self</em>, <em>order</em>). Return the bytes
of this array in a Python string.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_ToFile">
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>* <code class="sig-name descname">PyArray_ToFile</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> self</em>, FILE*<em> fp</em>, char*<em> sep</em>, char*<em> format</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_ToFile" title="Permalink to this definition">¶</a></dt>
<dd><p>Write the contents of <em>self</em> to the file pointer <em>fp</em> in C-style
contiguous fashion. Write the data as binary bytes if <em>sep</em> is the
string “”or <code class="docutils literal notranslate"><span class="pre">NULL</span></code>. Otherwise, write the contents of <em>self</em> as
text using the <em>sep</em> string as the item separator. Each item will
be printed to the file.  If the <em>format</em> string is not <code class="docutils literal notranslate"><span class="pre">NULL</span></code> or
“”, then it is a Python print statement format string showing how
the items are to be written.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_Dump">
int <code class="sig-name descname">PyArray_Dump</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> self</em>, <a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> file</em>, int<em> protocol</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_Dump" title="Permalink to this definition">¶</a></dt>
<dd><p>Pickle the object in <em>self</em> to the given <em>file</em> (either a string
or a Python file object). If <em>file</em> is a Python string it is
considered to be the name of a file which is then opened in binary
mode. The given <em>protocol</em> is used (if <em>protocol</em> is negative, or
the highest available is used). This is a simple wrapper around
cPickle.dump(<em>self</em>, <em>file</em>, <em>protocol</em>).</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_Dumps">
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>* <code class="sig-name descname">PyArray_Dumps</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> self</em>, int<em> protocol</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_Dumps" title="Permalink to this definition">¶</a></dt>
<dd><p>Pickle the object in <em>self</em> to a Python string and return it. Use
the Pickle <em>protocol</em> provided (or the highest available if
<em>protocol</em> is negative).</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_FillWithScalar">
int <code class="sig-name descname">PyArray_FillWithScalar</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> arr</em>, <a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> obj</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_FillWithScalar" title="Permalink to this definition">¶</a></dt>
<dd><p>Fill the array, <em>arr</em>, with the given scalar object, <em>obj</em>. The
object is first converted to the data type of <em>arr</em>, and then
copied into every location. A -1 is returned if an error occurs,
otherwise 0 is returned.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_View">
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>* <code class="sig-name descname">PyArray_View</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> self</em>, <a class="reference internal" href="types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>*<em> dtype</em>, <a class="reference external" href="https://docs.python.org/dev/c-api/type.html#c.PyTypeObject" title="(in Python v3.9)">PyTypeObject</a><em> *ptype</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_View" title="Permalink to this definition">¶</a></dt>
<dd><p>Equivalent to <a class="reference internal" href="../generated/numpy.ndarray.view.html#numpy.ndarray.view" title="numpy.ndarray.view"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ndarray.view</span></code></a> (<em>self</em>, <em>dtype</em>). Return a new
view of the array <em>self</em> as possibly a different data-type, <em>dtype</em>,
and different array subclass <em>ptype</em>.</p>
<p>If <em>dtype</em> is <code class="docutils literal notranslate"><span class="pre">NULL</span></code>, then the returned array will have the same
data type as <em>self</em>. The new data-type must be consistent with the
size of <em>self</em>. Either the itemsizes must be identical, or <em>self</em> must
be single-segment and the total number of bytes must be the same.
In the latter case the dimensions of the returned array will be
altered in the last (or first for Fortran-style contiguous arrays)
dimension. The data area of the returned array and self is exactly
the same.</p>
</dd></dl>

</div>
<div class="section" id="shape-manipulation">
<h3>Shape Manipulation<a class="headerlink" href="#shape-manipulation" title="Permalink to this headline">¶</a></h3>
<dl class="function">
<dt id="c.PyArray_Newshape">
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>* <code class="sig-name descname">PyArray_Newshape</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> self</em>, <a class="reference internal" href="types-and-structures.html#c.PyArray_Dims" title="PyArray_Dims">PyArray_Dims</a>*<em> newshape</em>, <a class="reference internal" href="#c.NPY_ORDER" title="NPY_ORDER">NPY_ORDER</a><em> order</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_Newshape" title="Permalink to this definition">¶</a></dt>
<dd><p>Result will be a new array (pointing to the same memory location
as <em>self</em> if possible), but having a shape given by <em>newshape</em>.
If the new shape is not compatible with the strides of <em>self</em>,
then a copy of the array with the new specified shape will be
returned.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_Reshape">
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>* <code class="sig-name descname">PyArray_Reshape</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> self</em>, <a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> shape</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_Reshape" title="Permalink to this definition">¶</a></dt>
<dd><p>Equivalent to <a class="reference internal" href="../generated/numpy.ndarray.reshape.html#numpy.ndarray.reshape" title="numpy.ndarray.reshape"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ndarray.reshape</span></code></a> (<em>self</em>, <em>shape</em>) where <em>shape</em> is a
sequence. Converts <em>shape</em> to a <a class="reference internal" href="types-and-structures.html#c.PyArray_Dims" title="PyArray_Dims"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyArray_Dims</span></code></a> structure and
calls <a class="reference internal" href="#c.PyArray_Newshape" title="PyArray_Newshape"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_Newshape</span></code></a> internally.
For back-ward compatibility – Not recommended</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_Squeeze">
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>* <code class="sig-name descname">PyArray_Squeeze</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> self</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_Squeeze" title="Permalink to this definition">¶</a></dt>
<dd><p>Equivalent to <a class="reference internal" href="../generated/numpy.ndarray.squeeze.html#numpy.ndarray.squeeze" title="numpy.ndarray.squeeze"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ndarray.squeeze</span></code></a> (<em>self</em>). Return a new view of <em>self</em>
with all of the dimensions of length 1 removed from the shape.</p>
</dd></dl>

<div class="admonition warning">
<p class="admonition-title">Warning</p>
<p>matrix objects are always 2-dimensional. Therefore,
<a class="reference internal" href="#c.PyArray_Squeeze" title="PyArray_Squeeze"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_Squeeze</span></code></a> has no effect on arrays of matrix sub-class.</p>
</div>
<dl class="function">
<dt id="c.PyArray_SwapAxes">
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>* <code class="sig-name descname">PyArray_SwapAxes</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> self</em>, int<em> a1</em>, int<em> a2</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_SwapAxes" title="Permalink to this definition">¶</a></dt>
<dd><p>Equivalent to <a class="reference internal" href="../generated/numpy.ndarray.swapaxes.html#numpy.ndarray.swapaxes" title="numpy.ndarray.swapaxes"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ndarray.swapaxes</span></code></a> (<em>self</em>, <em>a1</em>, <em>a2</em>). The returned
array is a new view of the data in <em>self</em> with the given axes,
<em>a1</em> and <em>a2</em>, swapped.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_Resize">
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>* <code class="sig-name descname">PyArray_Resize</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> self</em>, <a class="reference internal" href="types-and-structures.html#c.PyArray_Dims" title="PyArray_Dims">PyArray_Dims</a>*<em> newshape</em>, int<em> refcheck</em>, <a class="reference internal" href="#c.NPY_ORDER" title="NPY_ORDER">NPY_ORDER</a><em> fortran</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_Resize" title="Permalink to this definition">¶</a></dt>
<dd><p>Equivalent to <a class="reference internal" href="../generated/numpy.ndarray.resize.html#numpy.ndarray.resize" title="numpy.ndarray.resize"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ndarray.resize</span></code></a> (<em>self</em>, <em>newshape</em>, refcheck
<code class="docutils literal notranslate"><span class="pre">=</span></code> <em>refcheck</em>, order= fortran ). This function only works on
single-segment arrays. It changes the shape of <em>self</em> inplace and
will reallocate the memory for <em>self</em> if <em>newshape</em> has a
different total number of elements then the old shape. If
reallocation is necessary, then <em>self</em> must own its data, have
<em>self</em> - <code class="docutils literal notranslate"><span class="pre">&gt;base==NULL</span></code>, have <em>self</em> - <code class="docutils literal notranslate"><span class="pre">&gt;weakrefs==NULL</span></code>, and
(unless refcheck is 0) not be referenced by any other array.
The fortran argument can be <a class="reference internal" href="#c.NPY_ANYORDER" title="NPY_ANYORDER"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ANYORDER</span></code></a>, <a class="reference internal" href="#c.NPY_CORDER" title="NPY_CORDER"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_CORDER</span></code></a>,
or <a class="reference internal" href="#c.NPY_FORTRANORDER" title="NPY_FORTRANORDER"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_FORTRANORDER</span></code></a>. It currently has no effect. Eventually
it could be used to determine how the resize operation should view
the data when constructing a differently-dimensioned array.
Returns None on success and NULL on error.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_Transpose">
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>* <code class="sig-name descname">PyArray_Transpose</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> self</em>, <a class="reference internal" href="types-and-structures.html#c.PyArray_Dims" title="PyArray_Dims">PyArray_Dims</a>*<em> permute</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_Transpose" title="Permalink to this definition">¶</a></dt>
<dd><p>Equivalent to <a class="reference internal" href="../generated/numpy.ndarray.transpose.html#numpy.ndarray.transpose" title="numpy.ndarray.transpose"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ndarray.transpose</span></code></a> (<em>self</em>, <em>permute</em>). Permute the
axes of the ndarray object <em>self</em> according to the data structure
<em>permute</em> and return the result. If <em>permute</em> is <code class="docutils literal notranslate"><span class="pre">NULL</span></code>, then
the resulting array has its axes reversed. For example if <em>self</em>
has shape <img class="math" src="../../_images/math/cf46a7e7c9205a1787ab072d6fbf2d10882d0a14.svg" alt="10\times20\times30"/>, and <em>permute</em> <code class="docutils literal notranslate"><span class="pre">.ptr</span></code> is
(0,2,1) the shape of the result is <img class="math" src="../../_images/math/cc7506f6bfa21cd3001c1973ba288743c5f6286e.svg" alt="10\times30\times20."/> If
<em>permute</em> is <code class="docutils literal notranslate"><span class="pre">NULL</span></code>, the shape of the result is
<img class="math" src="../../_images/math/578d4b41b2a89dcdb0321578edd8603b0d425adc.svg" alt="30\times20\times10."/></p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_Flatten">
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>* <code class="sig-name descname">PyArray_Flatten</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> self</em>, <a class="reference internal" href="#c.NPY_ORDER" title="NPY_ORDER">NPY_ORDER</a><em> order</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_Flatten" title="Permalink to this definition">¶</a></dt>
<dd><p>Equivalent to <a class="reference internal" href="../generated/numpy.ndarray.flatten.html#numpy.ndarray.flatten" title="numpy.ndarray.flatten"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ndarray.flatten</span></code></a> (<em>self</em>, <em>order</em>). Return a 1-d copy
of the array. If <em>order</em> is <a class="reference internal" href="#c.NPY_FORTRANORDER" title="NPY_FORTRANORDER"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_FORTRANORDER</span></code></a> the elements are
scanned out in Fortran order (first-dimension varies the
fastest). If <em>order</em> is <a class="reference internal" href="#c.NPY_CORDER" title="NPY_CORDER"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_CORDER</span></code></a>, the elements of <code class="docutils literal notranslate"><span class="pre">self</span></code>
are scanned in C-order (last dimension varies the fastest). If
<em>order</em> <a class="reference internal" href="#c.NPY_ANYORDER" title="NPY_ANYORDER"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ANYORDER</span></code></a>, then the result of
<a class="reference internal" href="#c.PyArray_ISFORTRAN" title="PyArray_ISFORTRAN"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_ISFORTRAN</span></code></a> (<em>self</em>) is used to determine which order
to flatten.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_Ravel">
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>* <code class="sig-name descname">PyArray_Ravel</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> self</em>, <a class="reference internal" href="#c.NPY_ORDER" title="NPY_ORDER">NPY_ORDER</a><em> order</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_Ravel" title="Permalink to this definition">¶</a></dt>
<dd><p>Equivalent to <em>self</em>.ravel(<em>order</em>). Same basic functionality
as <a class="reference internal" href="#c.PyArray_Flatten" title="PyArray_Flatten"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_Flatten</span></code></a> (<em>self</em>, <em>order</em>) except if <em>order</em> is 0
and <em>self</em> is C-style contiguous, the shape is altered but no copy
is performed.</p>
</dd></dl>

</div>
<div class="section" id="item-selection-and-manipulation">
<h3>Item selection and manipulation<a class="headerlink" href="#item-selection-and-manipulation" title="Permalink to this headline">¶</a></h3>
<dl class="function">
<dt id="c.PyArray_TakeFrom">
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>* <code class="sig-name descname">PyArray_TakeFrom</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> self</em>, <a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> indices</em>, int<em> axis</em>, <a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> ret</em>, <a class="reference internal" href="#c.NPY_CLIPMODE" title="NPY_CLIPMODE">NPY_CLIPMODE</a><em> clipmode</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_TakeFrom" title="Permalink to this definition">¶</a></dt>
<dd><p>Equivalent to <a class="reference internal" href="../generated/numpy.ndarray.take.html#numpy.ndarray.take" title="numpy.ndarray.take"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ndarray.take</span></code></a> (<em>self</em>, <em>indices</em>, <em>axis</em>, <em>ret</em>,
<em>clipmode</em>) except <em>axis</em> =None in Python is obtained by setting
<em>axis</em> = <a class="reference internal" href="#c.NPY_MAXDIMS" title="NPY_MAXDIMS"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_MAXDIMS</span></code></a> in C. Extract the items from self
indicated by the integer-valued <em>indices</em> along the given <em>axis.</em>
The clipmode argument can be <a class="reference internal" href="#c.NPY_RAISE" title="NPY_RAISE"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_RAISE</span></code></a>, <a class="reference internal" href="#c.NPY_WRAP" title="NPY_WRAP"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_WRAP</span></code></a>, or
<a class="reference internal" href="#c.NPY_CLIP" title="NPY_CLIP"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_CLIP</span></code></a> to indicate what to do with out-of-bound indices. The
<em>ret</em> argument can specify an output array rather than having one
created internally.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_PutTo">
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>* <code class="sig-name descname">PyArray_PutTo</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> self</em>, <a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> values</em>, <a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> indices</em>, <a class="reference internal" href="#c.NPY_CLIPMODE" title="NPY_CLIPMODE">NPY_CLIPMODE</a><em> clipmode</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_PutTo" title="Permalink to this definition">¶</a></dt>
<dd><p>Equivalent to <em>self</em>.put(<em>values</em>, <em>indices</em>, <em>clipmode</em>
). Put <em>values</em> into <em>self</em> at the corresponding (flattened)
<em>indices</em>. If <em>values</em> is too small it will be repeated as
necessary.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_PutMask">
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>* <code class="sig-name descname">PyArray_PutMask</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> self</em>, <a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> values</em>, <a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> mask</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_PutMask" title="Permalink to this definition">¶</a></dt>
<dd><p>Place the <em>values</em> in <em>self</em> wherever corresponding positions
(using a flattened context) in <em>mask</em> are true. The <em>mask</em> and
<em>self</em> arrays must have the same total number of elements. If
<em>values</em> is too small, it will be repeated as necessary.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_Repeat">
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>* <code class="sig-name descname">PyArray_Repeat</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> self</em>, <a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> op</em>, int<em> axis</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_Repeat" title="Permalink to this definition">¶</a></dt>
<dd><p>Equivalent to <a class="reference internal" href="../generated/numpy.ndarray.repeat.html#numpy.ndarray.repeat" title="numpy.ndarray.repeat"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ndarray.repeat</span></code></a> (<em>self</em>, <em>op</em>, <em>axis</em>). Copy the
elements of <em>self</em>, <em>op</em> times along the given <em>axis</em>. Either
<em>op</em> is a scalar integer or a sequence of length <em>self</em>
-&gt;dimensions[ <em>axis</em> ] indicating how many times to repeat each
item along the axis.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_Choose">
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>* <code class="sig-name descname">PyArray_Choose</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> self</em>, <a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> op</em>, <a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> ret</em>, <a class="reference internal" href="#c.NPY_CLIPMODE" title="NPY_CLIPMODE">NPY_CLIPMODE</a><em> clipmode</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_Choose" title="Permalink to this definition">¶</a></dt>
<dd><p>Equivalent to <a class="reference internal" href="../generated/numpy.ndarray.choose.html#numpy.ndarray.choose" title="numpy.ndarray.choose"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ndarray.choose</span></code></a> (<em>self</em>, <em>op</em>, <em>ret</em>, <em>clipmode</em>).
Create a new array by selecting elements from the sequence of
arrays in <em>op</em> based on the integer values in <em>self</em>. The arrays
must all be broadcastable to the same shape and the entries in
<em>self</em> should be between 0 and len(<em>op</em>). The output is placed
in <em>ret</em> unless it is <code class="docutils literal notranslate"><span class="pre">NULL</span></code> in which case a new output is
created. The <em>clipmode</em> argument determines behavior for when
entries in <em>self</em> are not between 0 and len(<em>op</em>).</p>
<dl class="var">
<dt id="c.NPY_RAISE">
<code class="sig-name descname">NPY_RAISE</code><a class="headerlink" href="#c.NPY_RAISE" title="Permalink to this definition">¶</a></dt>
<dd><p>raise a ValueError;</p>
</dd></dl>

<dl class="var">
<dt id="c.NPY_WRAP">
<code class="sig-name descname">NPY_WRAP</code><a class="headerlink" href="#c.NPY_WRAP" title="Permalink to this definition">¶</a></dt>
<dd><p>wrap values &lt; 0 by adding len(<em>op</em>) and values &gt;=len(<em>op</em>)
by subtracting len(<em>op</em>) until they are in range;</p>
</dd></dl>

<dl class="var">
<dt id="c.NPY_CLIP">
<code class="sig-name descname">NPY_CLIP</code><a class="headerlink" href="#c.NPY_CLIP" title="Permalink to this definition">¶</a></dt>
<dd><p>all values are clipped to the region [0, len(<em>op</em>) ).</p>
</dd></dl>

</dd></dl>

<dl class="function">
<dt id="c.PyArray_Sort">
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>* <code class="sig-name descname">PyArray_Sort</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> self</em>, int<em> axis</em>, <a class="reference internal" href="#c.NPY_SORTKIND" title="NPY_SORTKIND">NPY_SORTKIND</a><em> kind</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_Sort" title="Permalink to this definition">¶</a></dt>
<dd><p>Equivalent to <a class="reference internal" href="../generated/numpy.ndarray.sort.html#numpy.ndarray.sort" title="numpy.ndarray.sort"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ndarray.sort</span></code></a> (<em>self</em>, <em>axis</em>, <em>kind</em>).
Return an array with the items of <em>self</em> sorted along <em>axis</em>. The array
is sorted using the algorithm denoted by <em>kind</em> , which is an integer/enum pointing
to the type of sorting algorithms used.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_ArgSort">
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>* <code class="sig-name descname">PyArray_ArgSort</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> self</em>, int<em> axis</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_ArgSort" title="Permalink to this definition">¶</a></dt>
<dd><p>Equivalent to <a class="reference internal" href="../generated/numpy.ndarray.argsort.html#numpy.ndarray.argsort" title="numpy.ndarray.argsort"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ndarray.argsort</span></code></a> (<em>self</em>, <em>axis</em>).
Return an array of indices such that selection of these indices
along the given <code class="docutils literal notranslate"><span class="pre">axis</span></code> would return a sorted version of <em>self</em>. If <em>self</em> -&gt;descr
is a data-type with fields defined, then self-&gt;descr-&gt;names is used
to determine the sort order. A comparison where the first field is equal
will use the second field and so on. To alter the sort order of a
structured array, create a new data-type with a different order of names
and construct a view of the array with that new data-type.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_LexSort">
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>* <code class="sig-name descname">PyArray_LexSort</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> sort_keys</em>, int<em> axis</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_LexSort" title="Permalink to this definition">¶</a></dt>
<dd><p>Given a sequence of arrays (<em>sort_keys</em>) of the same shape,
return an array of indices (similar to <a class="reference internal" href="#c.PyArray_ArgSort" title="PyArray_ArgSort"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_ArgSort</span></code></a> (…))
that would sort the arrays lexicographically. A lexicographic sort
specifies that when two keys are found to be equal, the order is
based on comparison of subsequent keys. A merge sort (which leaves
equal entries unmoved) is required to be defined for the
types. The sort is accomplished by sorting the indices first using
the first <em>sort_key</em> and then using the second <em>sort_key</em> and so
forth. This is equivalent to the lexsort(<em>sort_keys</em>, <em>axis</em>)
Python command. Because of the way the merge-sort works, be sure
to understand the order the <em>sort_keys</em> must be in (reversed from
the order you would use when comparing two elements).</p>
<p>If these arrays are all collected in a structured array, then
<a class="reference internal" href="#c.PyArray_Sort" title="PyArray_Sort"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_Sort</span></code></a> (…) can also be used to sort the array
directly.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_SearchSorted">
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>* <code class="sig-name descname">PyArray_SearchSorted</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> self</em>, <a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> values</em>, NPY_SEARCHSIDE<em> side</em>, <a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> perm</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_SearchSorted" title="Permalink to this definition">¶</a></dt>
<dd><p>Equivalent to <a class="reference internal" href="../generated/numpy.ndarray.searchsorted.html#numpy.ndarray.searchsorted" title="numpy.ndarray.searchsorted"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ndarray.searchsorted</span></code></a> (<em>self</em>, <em>values</em>, <em>side</em>,
<em>perm</em>). Assuming <em>self</em> is a 1-d array in ascending order, then the
output is an array of indices the same shape as <em>values</em> such that, if
the elements in <em>values</em> were inserted before the indices, the order of
<em>self</em> would be preserved. No checking is done on whether or not self is
in ascending order.</p>
<p>The <em>side</em> argument indicates whether the index returned should be that of
the first suitable location (if <code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_SEARCHLEFT</span></code>) or of the last
(if <code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_SEARCHRIGHT</span></code>).</p>
<p>The <em>sorter</em> argument, if not <code class="docutils literal notranslate"><span class="pre">NULL</span></code>, must be a 1D array of integer
indices the same length as <em>self</em>, that sorts it into ascending order.
This is typically the result of a call to <a class="reference internal" href="#c.PyArray_ArgSort" title="PyArray_ArgSort"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_ArgSort</span></code></a> (…)
Binary search is used to find the required insertion points.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_Partition">
int <code class="sig-name descname">PyArray_Partition</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a><em> *self</em>, <a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a> *<em> ktharray</em>, int<em> axis</em>, NPY_SELECTKIND<em> which</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_Partition" title="Permalink to this definition">¶</a></dt>
<dd><p>Equivalent to <a class="reference internal" href="../generated/numpy.ndarray.partition.html#numpy.ndarray.partition" title="numpy.ndarray.partition"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ndarray.partition</span></code></a> (<em>self</em>, <em>ktharray</em>, <em>axis</em>,
<em>kind</em>). Partitions the array so that the values of the element indexed by
<em>ktharray</em> are in the positions they would be if the array is fully sorted
and places all elements smaller than the kth before and all elements equal
or greater after the kth element. The ordering of all elements within the
partitions is undefined.
If <em>self</em>-&gt;descr is a data-type with fields defined, then
self-&gt;descr-&gt;names is used to determine the sort order. A comparison where
the first field is equal will use the second field and so on. To alter the
sort order of a structured array, create a new data-type with a different
order of names and construct a view of the array with that new data-type.
Returns zero on success and -1 on failure.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_ArgPartition">
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>* <code class="sig-name descname">PyArray_ArgPartition</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a><em> *op</em>, <a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a> *<em> ktharray</em>, int<em> axis</em>, NPY_SELECTKIND<em> which</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_ArgPartition" title="Permalink to this definition">¶</a></dt>
<dd><p>Equivalent to <a class="reference internal" href="../generated/numpy.ndarray.argpartition.html#numpy.ndarray.argpartition" title="numpy.ndarray.argpartition"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ndarray.argpartition</span></code></a> (<em>self</em>, <em>ktharray</em>, <em>axis</em>,
<em>kind</em>). Return an array of indices such that selection of these indices
along the given <code class="docutils literal notranslate"><span class="pre">axis</span></code> would return a partitioned version of <em>self</em>.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_Diagonal">
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>* <code class="sig-name descname">PyArray_Diagonal</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> self</em>, int<em> offset</em>, int<em> axis1</em>, int<em> axis2</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_Diagonal" title="Permalink to this definition">¶</a></dt>
<dd><p>Equivalent to <a class="reference internal" href="../generated/numpy.ndarray.diagonal.html#numpy.ndarray.diagonal" title="numpy.ndarray.diagonal"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ndarray.diagonal</span></code></a> (<em>self</em>, <em>offset</em>, <em>axis1</em>, <em>axis2</em>
). Return the <em>offset</em> diagonals of the 2-d arrays defined by
<em>axis1</em> and <em>axis2</em>.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_CountNonzero">
<a class="reference internal" href="dtype.html#c.npy_intp" title="npy_intp">npy_intp</a> <code class="sig-name descname">PyArray_CountNonzero</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> self</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_CountNonzero" title="Permalink to this definition">¶</a></dt>
<dd><div class="versionadded">
<p><span class="versionmodified added">New in version 1.6.</span></p>
</div>
<p>Counts the number of non-zero elements in the array object <em>self</em>.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_Nonzero">
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>* <code class="sig-name descname">PyArray_Nonzero</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> self</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_Nonzero" title="Permalink to this definition">¶</a></dt>
<dd><p>Equivalent to <a class="reference internal" href="../generated/numpy.ndarray.nonzero.html#numpy.ndarray.nonzero" title="numpy.ndarray.nonzero"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ndarray.nonzero</span></code></a> (<em>self</em>). Returns a tuple of index
arrays that select elements of <em>self</em> that are nonzero. If (nd=
<a class="reference internal" href="#c.PyArray_NDIM" title="PyArray_NDIM"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_NDIM</span></code></a> ( <code class="docutils literal notranslate"><span class="pre">self</span></code> ))==1, then a single index array is
returned. The index arrays have data type <a class="reference internal" href="dtype.html#c.NPY_INTP" title="NPY_INTP"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_INTP</span></code></a>. If a
tuple is returned (nd <img class="math" src="../../_images/math/64a34fb7ea4b10dd7abed3737173f7323bcbdbc3.svg" alt="\neq"/> 1), then its length is nd.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_Compress">
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>* <code class="sig-name descname">PyArray_Compress</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> self</em>, <a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> condition</em>, int<em> axis</em>, <a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> out</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_Compress" title="Permalink to this definition">¶</a></dt>
<dd><p>Equivalent to <a class="reference internal" href="../generated/numpy.ndarray.compress.html#numpy.ndarray.compress" title="numpy.ndarray.compress"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ndarray.compress</span></code></a> (<em>self</em>, <em>condition</em>, <em>axis</em>
). Return the elements along <em>axis</em> corresponding to elements of
<em>condition</em> that are true.</p>
</dd></dl>

</div>
<div class="section" id="calculation">
<h3>Calculation<a class="headerlink" href="#calculation" title="Permalink to this headline">¶</a></h3>
<div class="admonition tip">
<p class="admonition-title">Tip</p>
<p>Pass in <a class="reference internal" href="#c.NPY_MAXDIMS" title="NPY_MAXDIMS"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_MAXDIMS</span></code></a> for axis in order to achieve the same
effect that is obtained by passing in <code class="docutils literal notranslate"><span class="pre">axis=None</span></code> in Python
(treating the array as a 1-d array).</p>
</div>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>The out argument specifies where to place the result. If out is
NULL, then the output array is created, otherwise the output is
placed in out which must be the correct size and type. A new
reference to the output array is always returned even when out
is not NULL. The caller of the routine has the responsibility
to <code class="docutils literal notranslate"><span class="pre">Py_DECREF</span></code> out if not NULL or a memory-leak will occur.</p>
</div>
<dl class="function">
<dt id="c.PyArray_ArgMax">
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>* <code class="sig-name descname">PyArray_ArgMax</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> self</em>, int<em> axis</em>, <a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> out</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_ArgMax" title="Permalink to this definition">¶</a></dt>
<dd><p>Equivalent to <a class="reference internal" href="../generated/numpy.ndarray.argmax.html#numpy.ndarray.argmax" title="numpy.ndarray.argmax"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ndarray.argmax</span></code></a> (<em>self</em>, <em>axis</em>). Return the index of
the largest element of <em>self</em> along <em>axis</em>.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_ArgMin">
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>* <code class="sig-name descname">PyArray_ArgMin</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> self</em>, int<em> axis</em>, <a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> out</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_ArgMin" title="Permalink to this definition">¶</a></dt>
<dd><p>Equivalent to <a class="reference internal" href="../generated/numpy.ndarray.argmin.html#numpy.ndarray.argmin" title="numpy.ndarray.argmin"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ndarray.argmin</span></code></a> (<em>self</em>, <em>axis</em>). Return the index of
the smallest element of <em>self</em> along <em>axis</em>.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_Max">
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>* <code class="sig-name descname">PyArray_Max</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> self</em>, int<em> axis</em>, <a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> out</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_Max" title="Permalink to this definition">¶</a></dt>
<dd><p>Equivalent to <a class="reference internal" href="../generated/numpy.ndarray.max.html#numpy.ndarray.max" title="numpy.ndarray.max"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ndarray.max</span></code></a> (<em>self</em>, <em>axis</em>). Returns the largest
element of <em>self</em> along the given <em>axis</em>. When the result is a single
element, returns a numpy scalar instead of an ndarray.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_Min">
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>* <code class="sig-name descname">PyArray_Min</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> self</em>, int<em> axis</em>, <a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> out</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_Min" title="Permalink to this definition">¶</a></dt>
<dd><p>Equivalent to <a class="reference internal" href="../generated/numpy.ndarray.min.html#numpy.ndarray.min" title="numpy.ndarray.min"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ndarray.min</span></code></a> (<em>self</em>, <em>axis</em>). Return the smallest
element of <em>self</em> along the given <em>axis</em>. When the result is a single
element, returns a numpy scalar instead of an ndarray.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_Ptp">
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>* <code class="sig-name descname">PyArray_Ptp</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> self</em>, int<em> axis</em>, <a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> out</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_Ptp" title="Permalink to this definition">¶</a></dt>
<dd><p>Equivalent to <a class="reference internal" href="../generated/numpy.ndarray.ptp.html#numpy.ndarray.ptp" title="numpy.ndarray.ptp"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ndarray.ptp</span></code></a> (<em>self</em>, <em>axis</em>). Return the difference
between the largest element of <em>self</em> along <em>axis</em> and the
smallest element of <em>self</em> along <em>axis</em>. When the result is a single
element, returns a numpy scalar instead of an ndarray.</p>
</dd></dl>

<div class="admonition note">
<p class="admonition-title">Note</p>
<p>The rtype argument specifies the data-type the reduction should
take place over. This is important if the data-type of the array
is not “large” enough to handle the output. By default, all
integer data-types are made at least as large as <a class="reference internal" href="dtype.html#c.NPY_LONG" title="NPY_LONG"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_LONG</span></code></a>
for the “add” and “multiply” ufuncs (which form the basis for
mean, sum, cumsum, prod, and cumprod functions).</p>
</div>
<dl class="function">
<dt id="c.PyArray_Mean">
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>* <code class="sig-name descname">PyArray_Mean</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> self</em>, int<em> axis</em>, int<em> rtype</em>, <a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> out</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_Mean" title="Permalink to this definition">¶</a></dt>
<dd><p>Equivalent to <a class="reference internal" href="../generated/numpy.ndarray.mean.html#numpy.ndarray.mean" title="numpy.ndarray.mean"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ndarray.mean</span></code></a> (<em>self</em>, <em>axis</em>, <em>rtype</em>). Returns the
mean of the elements along the given <em>axis</em>, using the enumerated
type <em>rtype</em> as the data type to sum in. Default sum behavior is
obtained using <a class="reference internal" href="dtype.html#c.NPY_NOTYPE" title="NPY_NOTYPE"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_NOTYPE</span></code></a> for <em>rtype</em>.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_Trace">
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>* <code class="sig-name descname">PyArray_Trace</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> self</em>, int<em> offset</em>, int<em> axis1</em>, int<em> axis2</em>, int<em> rtype</em>, <a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> out</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_Trace" title="Permalink to this definition">¶</a></dt>
<dd><p>Equivalent to <a class="reference internal" href="../generated/numpy.ndarray.trace.html#numpy.ndarray.trace" title="numpy.ndarray.trace"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ndarray.trace</span></code></a> (<em>self</em>, <em>offset</em>, <em>axis1</em>, <em>axis2</em>,
<em>rtype</em>). Return the sum (using <em>rtype</em> as the data type of
summation) over the <em>offset</em> diagonal elements of the 2-d arrays
defined by <em>axis1</em> and <em>axis2</em> variables. A positive offset
chooses diagonals above the main diagonal. A negative offset
selects diagonals below the main diagonal.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_Clip">
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>* <code class="sig-name descname">PyArray_Clip</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> self</em>, <a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> min</em>, <a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> max</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_Clip" title="Permalink to this definition">¶</a></dt>
<dd><p>Equivalent to <a class="reference internal" href="../generated/numpy.ndarray.clip.html#numpy.ndarray.clip" title="numpy.ndarray.clip"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ndarray.clip</span></code></a> (<em>self</em>, <em>min</em>, <em>max</em>). Clip an array,
<em>self</em>, so that values larger than <em>max</em> are fixed to <em>max</em> and
values less than <em>min</em> are fixed to <em>min</em>.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_Conjugate">
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>* <code class="sig-name descname">PyArray_Conjugate</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> self</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_Conjugate" title="Permalink to this definition">¶</a></dt>
<dd><p>Equivalent to <a class="reference internal" href="../generated/numpy.ndarray.conjugate.html#numpy.ndarray.conjugate" title="numpy.ndarray.conjugate"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ndarray.conjugate</span></code></a> (<em>self</em>).
Return the complex conjugate of <em>self</em>. If <em>self</em> is not of
complex data type, then return <em>self</em> with a reference.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_Round">
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>* <code class="sig-name descname">PyArray_Round</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> self</em>, int<em> decimals</em>, <a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> out</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_Round" title="Permalink to this definition">¶</a></dt>
<dd><p>Equivalent to <a class="reference internal" href="../generated/numpy.ndarray.round.html#numpy.ndarray.round" title="numpy.ndarray.round"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ndarray.round</span></code></a> (<em>self</em>, <em>decimals</em>, <em>out</em>). Returns
the array with elements rounded to the nearest decimal place. The
decimal place is defined as the <img class="math" src="../../_images/math/d6748e572d24226af44d5f0bfe87cd60fa8b8026.svg" alt="10^{-\textrm{decimals}}"/>
digit so that negative <em>decimals</em> cause rounding to the nearest 10’s, 100’s, etc. If out is <code class="docutils literal notranslate"><span class="pre">NULL</span></code>, then the output array is created, otherwise the output is placed in <em>out</em> which must be the correct size and type.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_Std">
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>* <code class="sig-name descname">PyArray_Std</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> self</em>, int<em> axis</em>, int<em> rtype</em>, <a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> out</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_Std" title="Permalink to this definition">¶</a></dt>
<dd><p>Equivalent to <a class="reference internal" href="../generated/numpy.ndarray.std.html#numpy.ndarray.std" title="numpy.ndarray.std"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ndarray.std</span></code></a> (<em>self</em>, <em>axis</em>, <em>rtype</em>). Return the
standard deviation using data along <em>axis</em> converted to data type
<em>rtype</em>.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_Sum">
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>* <code class="sig-name descname">PyArray_Sum</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> self</em>, int<em> axis</em>, int<em> rtype</em>, <a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> out</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_Sum" title="Permalink to this definition">¶</a></dt>
<dd><p>Equivalent to <a class="reference internal" href="../generated/numpy.ndarray.sum.html#numpy.ndarray.sum" title="numpy.ndarray.sum"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ndarray.sum</span></code></a> (<em>self</em>, <em>axis</em>, <em>rtype</em>). Return 1-d
vector sums of elements in <em>self</em> along <em>axis</em>. Perform the sum
after converting data to data type <em>rtype</em>.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_CumSum">
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>* <code class="sig-name descname">PyArray_CumSum</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> self</em>, int<em> axis</em>, int<em> rtype</em>, <a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> out</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_CumSum" title="Permalink to this definition">¶</a></dt>
<dd><p>Equivalent to <a class="reference internal" href="../generated/numpy.ndarray.cumsum.html#numpy.ndarray.cumsum" title="numpy.ndarray.cumsum"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ndarray.cumsum</span></code></a> (<em>self</em>, <em>axis</em>, <em>rtype</em>). Return
cumulative 1-d sums of elements in <em>self</em> along <em>axis</em>. Perform
the sum after converting data to data type <em>rtype</em>.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_Prod">
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>* <code class="sig-name descname">PyArray_Prod</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> self</em>, int<em> axis</em>, int<em> rtype</em>, <a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> out</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_Prod" title="Permalink to this definition">¶</a></dt>
<dd><p>Equivalent to <a class="reference internal" href="../generated/numpy.ndarray.prod.html#numpy.ndarray.prod" title="numpy.ndarray.prod"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ndarray.prod</span></code></a> (<em>self</em>, <em>axis</em>, <em>rtype</em>). Return 1-d
products of elements in <em>self</em> along <em>axis</em>. Perform the product
after converting data to data type <em>rtype</em>.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_CumProd">
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>* <code class="sig-name descname">PyArray_CumProd</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> self</em>, int<em> axis</em>, int<em> rtype</em>, <a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> out</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_CumProd" title="Permalink to this definition">¶</a></dt>
<dd><p>Equivalent to <a class="reference internal" href="../generated/numpy.ndarray.cumprod.html#numpy.ndarray.cumprod" title="numpy.ndarray.cumprod"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ndarray.cumprod</span></code></a> (<em>self</em>, <em>axis</em>, <em>rtype</em>). Return
1-d cumulative products of elements in <code class="docutils literal notranslate"><span class="pre">self</span></code> along <code class="docutils literal notranslate"><span class="pre">axis</span></code>.
Perform the product after converting data to data type <code class="docutils literal notranslate"><span class="pre">rtype</span></code>.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_All">
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>* <code class="sig-name descname">PyArray_All</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> self</em>, int<em> axis</em>, <a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> out</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_All" title="Permalink to this definition">¶</a></dt>
<dd><p>Equivalent to <a class="reference internal" href="../generated/numpy.ndarray.all.html#numpy.ndarray.all" title="numpy.ndarray.all"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ndarray.all</span></code></a> (<em>self</em>, <em>axis</em>). Return an array with
True elements for every 1-d sub-array of <code class="docutils literal notranslate"><span class="pre">self</span></code> defined by
<code class="docutils literal notranslate"><span class="pre">axis</span></code> in which all the elements are True.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_Any">
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>* <code class="sig-name descname">PyArray_Any</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> self</em>, int<em> axis</em>, <a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> out</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_Any" title="Permalink to this definition">¶</a></dt>
<dd><p>Equivalent to <a class="reference internal" href="../generated/numpy.ndarray.any.html#numpy.ndarray.any" title="numpy.ndarray.any"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ndarray.any</span></code></a> (<em>self</em>, <em>axis</em>). Return an array with
True elements for every 1-d sub-array of <em>self</em> defined by <em>axis</em>
in which any of the elements are True.</p>
</dd></dl>

</div>
</div>
<div class="section" id="functions">
<h2>Functions<a class="headerlink" href="#functions" title="Permalink to this headline">¶</a></h2>
<div class="section" id="array-functions">
<h3>Array Functions<a class="headerlink" href="#array-functions" title="Permalink to this headline">¶</a></h3>
<dl class="function">
<dt id="c.PyArray_AsCArray">
int <code class="sig-name descname">PyArray_AsCArray</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>**<em> op</em>, void*<em> ptr</em>, <a class="reference internal" href="dtype.html#c.npy_intp" title="npy_intp">npy_intp</a>*<em> dims</em>, int<em> nd</em>, int<em> typenum</em>, int<em> itemsize</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_AsCArray" title="Permalink to this definition">¶</a></dt>
<dd><p>Sometimes it is useful to access a multidimensional array as a
C-style multi-dimensional array so that algorithms can be
implemented using C’s a[i][j][k] syntax. This routine returns a
pointer, <em>ptr</em>, that simulates this kind of C-style array, for
1-, 2-, and 3-d ndarrays.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>op</strong> – The address to any Python object. This Python object will be replaced
with an equivalent well-behaved, C-style contiguous, ndarray of the
given data type specified by the last two arguments. Be sure that
stealing a reference in this way to the input object is justified.</p></li>
<li><p><strong>ptr</strong> – The address to a (ctype* for 1-d, ctype** for 2-d or ctype*** for 3-d)
variable where ctype is the equivalent C-type for the data type. On
return, <em>ptr</em> will be addressable as a 1-d, 2-d, or 3-d array.</p></li>
<li><p><strong>dims</strong> – An output array that contains the shape of the array object. This
array gives boundaries on any looping that will take place.</p></li>
<li><p><strong>nd</strong> – The dimensionality of the array (1, 2, or 3).</p></li>
<li><p><strong>typenum</strong> – The expected data type of the array.</p></li>
<li><p><strong>itemsize</strong> – This argument is only needed when <em>typenum</em> represents a
flexible array. Otherwise it should be 0.</p></li>
</ul>
</dd>
</dl>
</dd></dl>

<div class="admonition note">
<p class="admonition-title">Note</p>
<p>The simulation of a C-style array is not complete for 2-d and 3-d
arrays. For example, the simulated arrays of pointers cannot be passed
to subroutines expecting specific, statically-defined 2-d and 3-d
arrays. To pass to functions requiring those kind of inputs, you must
statically define the required array and copy data.</p>
</div>
<dl class="function">
<dt id="c.PyArray_Free">
int <code class="sig-name descname">PyArray_Free</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> op</em>, void*<em> ptr</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_Free" title="Permalink to this definition">¶</a></dt>
<dd><p>Must be called with the same objects and memory locations returned
from <a class="reference internal" href="#c.PyArray_AsCArray" title="PyArray_AsCArray"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_AsCArray</span></code></a> (…). This function cleans up memory
that otherwise would get leaked.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_Concatenate">
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>* <code class="sig-name descname">PyArray_Concatenate</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> obj</em>, int<em> axis</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_Concatenate" title="Permalink to this definition">¶</a></dt>
<dd><p>Join the sequence of objects in <em>obj</em> together along <em>axis</em> into a
single array. If the dimensions or types are not compatible an
error is raised.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_InnerProduct">
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>* <code class="sig-name descname">PyArray_InnerProduct</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> obj1</em>, <a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> obj2</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_InnerProduct" title="Permalink to this definition">¶</a></dt>
<dd><p>Compute a product-sum over the last dimensions of <em>obj1</em> and
<em>obj2</em>. Neither array is conjugated.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_MatrixProduct">
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>* <code class="sig-name descname">PyArray_MatrixProduct</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> obj1</em>, <a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> obj</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_MatrixProduct" title="Permalink to this definition">¶</a></dt>
<dd><p>Compute a product-sum over the last dimension of <em>obj1</em> and the
second-to-last dimension of <em>obj2</em>. For 2-d arrays this is a
matrix-product. Neither array is conjugated.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_MatrixProduct2">
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>* <code class="sig-name descname">PyArray_MatrixProduct2</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> obj1</em>, <a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> obj</em>, <a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> out</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_MatrixProduct2" title="Permalink to this definition">¶</a></dt>
<dd><div class="versionadded">
<p><span class="versionmodified added">New in version 1.6.</span></p>
</div>
<p>Same as PyArray_MatrixProduct, but store the result in <em>out</em>.  The
output array must have the correct shape, type, and be
C-contiguous, or an exception is raised.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_EinsteinSum">
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>* <code class="sig-name descname">PyArray_EinsteinSum</code><span class="sig-paren">(</span>char*<em> subscripts</em>, <a class="reference internal" href="dtype.html#c.npy_intp" title="npy_intp">npy_intp</a><em> nop</em>, <a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>**<em> op_in</em>, <a class="reference internal" href="types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>*<em> dtype</em>, <a class="reference internal" href="#c.NPY_ORDER" title="NPY_ORDER">NPY_ORDER</a><em> order</em>, <a class="reference internal" href="#c.NPY_CASTING" title="NPY_CASTING">NPY_CASTING</a><em> casting</em>, <a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> out</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_EinsteinSum" title="Permalink to this definition">¶</a></dt>
<dd><div class="versionadded">
<p><span class="versionmodified added">New in version 1.6.</span></p>
</div>
<p>Applies the Einstein summation convention to the array operands
provided, returning a new array or placing the result in <em>out</em>.
The string in <em>subscripts</em> is a comma separated list of index
letters. The number of operands is in <em>nop</em>, and <em>op_in</em> is an
array containing those operands. The data type of the output can
be forced with <em>dtype</em>, the output order can be forced with <em>order</em>
(<a class="reference internal" href="#c.NPY_KEEPORDER" title="NPY_KEEPORDER"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_KEEPORDER</span></code></a> is recommended), and when <em>dtype</em> is specified,
<em>casting</em> indicates how permissive the data conversion should be.</p>
<p>See the <a class="reference internal" href="../generated/numpy.einsum.html#numpy.einsum" title="numpy.einsum"><code class="xref py py-func docutils literal notranslate"><span class="pre">einsum</span></code></a> function for more details.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_CopyAndTranspose">
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>* <code class="sig-name descname">PyArray_CopyAndTranspose</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a> *<em> op</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_CopyAndTranspose" title="Permalink to this definition">¶</a></dt>
<dd><p>A specialized copy and transpose function that works only for 2-d
arrays. The returned array is a transposed copy of <em>op</em>.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_Correlate">
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>* <code class="sig-name descname">PyArray_Correlate</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> op1</em>, <a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> op2</em>, int<em> mode</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_Correlate" title="Permalink to this definition">¶</a></dt>
<dd><p>Compute the 1-d correlation of the 1-d arrays <em>op1</em> and <em>op2</em>
. The correlation is computed at each output point by multiplying
<em>op1</em> by a shifted version of <em>op2</em> and summing the result. As a
result of the shift, needed values outside of the defined range of
<em>op1</em> and <em>op2</em> are interpreted as zero. The mode determines how
many shifts to return: 0 - return only shifts that did not need to
assume zero- values; 1 - return an object that is the same size as
<em>op1</em>, 2 - return all possible shifts (any overlap at all is
accepted).</p>
<p class="rubric">Notes</p>
<p>This does not compute the usual correlation: if op2 is larger than op1, the
arguments are swapped, and the conjugate is never taken for complex arrays.
See PyArray_Correlate2 for the usual signal processing correlation.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_Correlate2">
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>* <code class="sig-name descname">PyArray_Correlate2</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> op1</em>, <a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> op2</em>, int<em> mode</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_Correlate2" title="Permalink to this definition">¶</a></dt>
<dd><p>Updated version of PyArray_Correlate, which uses the usual definition of
correlation for 1d arrays. The correlation is computed at each output point
by multiplying <em>op1</em> by a shifted version of <em>op2</em> and summing the result.
As a result of the shift, needed values outside of the defined range of
<em>op1</em> and <em>op2</em> are interpreted as zero. The mode determines how many
shifts to return: 0 - return only shifts that did not need to assume zero-
values; 1 - return an object that is the same size as <em>op1</em>, 2 - return all
possible shifts (any overlap at all is accepted).</p>
<p class="rubric">Notes</p>
<p>Compute z as follows:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">z</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="o">=</span> <span class="n">sum_n</span> <span class="n">op1</span><span class="p">[</span><span class="n">n</span><span class="p">]</span> <span class="o">*</span> <span class="n">conj</span><span class="p">(</span><span class="n">op2</span><span class="p">[</span><span class="n">n</span><span class="o">+</span><span class="n">k</span><span class="p">])</span>
</pre></div>
</div>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_Where">
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>* <code class="sig-name descname">PyArray_Where</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> condition</em>, <a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> x</em>, <a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> y</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_Where" title="Permalink to this definition">¶</a></dt>
<dd><p>If both <code class="docutils literal notranslate"><span class="pre">x</span></code> and <code class="docutils literal notranslate"><span class="pre">y</span></code> are <code class="docutils literal notranslate"><span class="pre">NULL</span></code>, then return
<a class="reference internal" href="#c.PyArray_Nonzero" title="PyArray_Nonzero"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_Nonzero</span></code></a> (<em>condition</em>). Otherwise, both <em>x</em> and <em>y</em>
must be given and the object returned is shaped like <em>condition</em>
and has elements of <em>x</em> and <em>y</em> where <em>condition</em> is respectively
True or False.</p>
</dd></dl>

</div>
<div class="section" id="other-functions">
<h3>Other functions<a class="headerlink" href="#other-functions" title="Permalink to this headline">¶</a></h3>
<dl class="function">
<dt id="c.PyArray_CheckStrides">
Bool <code class="sig-name descname">PyArray_CheckStrides</code><span class="sig-paren">(</span>int<em> elsize</em>, int<em> nd</em>, <a class="reference internal" href="dtype.html#c.npy_intp" title="npy_intp">npy_intp</a><em> numbytes</em>, <a class="reference internal" href="dtype.html#c.npy_intp" title="npy_intp">npy_intp</a> const*<em> dims</em>, <a class="reference internal" href="dtype.html#c.npy_intp" title="npy_intp">npy_intp</a> const*<em> newstrides</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_CheckStrides" title="Permalink to this definition">¶</a></dt>
<dd><p>Determine if <em>newstrides</em> is a strides array consistent with the
memory of an <em>nd</em> -dimensional array with shape <code class="docutils literal notranslate"><span class="pre">dims</span></code> and
element-size, <em>elsize</em>. The <em>newstrides</em> array is checked to see
if jumping by the provided number of bytes in each direction will
ever mean jumping more than <em>numbytes</em> which is the assumed size
of the available memory segment. If <em>numbytes</em> is 0, then an
equivalent <em>numbytes</em> is computed assuming <em>nd</em>, <em>dims</em>, and
<em>elsize</em> refer to a single-segment array. Return <a class="reference internal" href="#c.NPY_TRUE" title="NPY_TRUE"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_TRUE</span></code></a> if
<em>newstrides</em> is acceptable, otherwise return <a class="reference internal" href="#c.NPY_FALSE" title="NPY_FALSE"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_FALSE</span></code></a>.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_MultiplyList">
<a class="reference internal" href="dtype.html#c.npy_intp" title="npy_intp">npy_intp</a> <code class="sig-name descname">PyArray_MultiplyList</code><span class="sig-paren">(</span><a class="reference internal" href="dtype.html#c.npy_intp" title="npy_intp">npy_intp</a> const*<em> seq</em>, int<em> n</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_MultiplyList" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="function">
<dt id="c.PyArray_MultiplyIntList">
int <code class="sig-name descname">PyArray_MultiplyIntList</code><span class="sig-paren">(</span>int const*<em> seq</em>, int<em> n</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_MultiplyIntList" title="Permalink to this definition">¶</a></dt>
<dd><p>Both of these routines multiply an <em>n</em> -length array, <em>seq</em>, of
integers and return the result. No overflow checking is performed.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_CompareLists">
int <code class="sig-name descname">PyArray_CompareLists</code><span class="sig-paren">(</span><a class="reference internal" href="dtype.html#c.npy_intp" title="npy_intp">npy_intp</a> const*<em> l1</em>, <a class="reference internal" href="dtype.html#c.npy_intp" title="npy_intp">npy_intp</a> const*<em> l2</em>, int<em> n</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_CompareLists" title="Permalink to this definition">¶</a></dt>
<dd><p>Given two <em>n</em> -length arrays of integers, <em>l1</em>, and <em>l2</em>, return
1 if the lists are identical; otherwise, return 0.</p>
</dd></dl>

</div>
</div>
<div class="section" id="auxiliary-data-with-object-semantics">
<h2>Auxiliary Data With Object Semantics<a class="headerlink" href="#auxiliary-data-with-object-semantics" title="Permalink to this headline">¶</a></h2>
<div class="versionadded">
<p><span class="versionmodified added">New in version 1.7.0.</span></p>
</div>
<dl class="type">
<dt id="c.NpyAuxData">
<code class="sig-name descname">NpyAuxData</code><a class="headerlink" href="#c.NpyAuxData" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<p>When working with more complex dtypes which are composed of other dtypes,
such as the struct dtype, creating inner loops that manipulate the dtypes
requires carrying along additional data. NumPy supports this idea
through a struct <a class="reference internal" href="#c.NpyAuxData" title="NpyAuxData"><code class="xref c c-type docutils literal notranslate"><span class="pre">NpyAuxData</span></code></a>, mandating a few conventions so that
it is possible to do this.</p>
<p>Defining an <a class="reference internal" href="#c.NpyAuxData" title="NpyAuxData"><code class="xref c c-type docutils literal notranslate"><span class="pre">NpyAuxData</span></code></a> is similar to defining a class in C++,
but the object semantics have to be tracked manually since the API is in C.
Here’s an example for a function which doubles up an element using
an element copier function as a primitive.:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">typedef</span> <span class="n">struct</span> <span class="p">{</span>
    <span class="n">NpyAuxData</span> <span class="n">base</span><span class="p">;</span>
    <span class="n">ElementCopier_Func</span> <span class="o">*</span><span class="n">func</span><span class="p">;</span>
    <span class="n">NpyAuxData</span> <span class="o">*</span><span class="n">funcdata</span><span class="p">;</span>
<span class="p">}</span> <span class="n">eldoubler_aux_data</span><span class="p">;</span>

<span class="n">void</span> <span class="n">free_element_doubler_aux_data</span><span class="p">(</span><span class="n">NpyAuxData</span> <span class="o">*</span><span class="n">data</span><span class="p">)</span>
<span class="p">{</span>
    <span class="n">eldoubler_aux_data</span> <span class="o">*</span><span class="n">d</span> <span class="o">=</span> <span class="p">(</span><span class="n">eldoubler_aux_data</span> <span class="o">*</span><span class="p">)</span><span class="n">data</span><span class="p">;</span>
    <span class="o">/*</span> <span class="n">Free</span> <span class="n">the</span> <span class="n">memory</span> <span class="n">owned</span> <span class="n">by</span> <span class="n">this</span> <span class="n">auxdata</span> <span class="o">*/</span>
    <span class="n">NPY_AUXDATA_FREE</span><span class="p">(</span><span class="n">d</span><span class="o">-&gt;</span><span class="n">funcdata</span><span class="p">);</span>
    <span class="n">PyArray_free</span><span class="p">(</span><span class="n">d</span><span class="p">);</span>
<span class="p">}</span>

<span class="n">NpyAuxData</span> <span class="o">*</span><span class="n">clone_element_doubler_aux_data</span><span class="p">(</span><span class="n">NpyAuxData</span> <span class="o">*</span><span class="n">data</span><span class="p">)</span>
<span class="p">{</span>
    <span class="n">eldoubler_aux_data</span> <span class="o">*</span><span class="n">ret</span> <span class="o">=</span> <span class="n">PyArray_malloc</span><span class="p">(</span><span class="n">sizeof</span><span class="p">(</span><span class="n">eldoubler_aux_data</span><span class="p">));</span>
    <span class="k">if</span> <span class="p">(</span><span class="n">ret</span> <span class="o">==</span> <span class="n">NULL</span><span class="p">)</span> <span class="p">{</span>
        <span class="k">return</span> <span class="n">NULL</span><span class="p">;</span>
    <span class="p">}</span>

    <span class="o">/*</span> <span class="n">Raw</span> <span class="n">copy</span> <span class="n">of</span> <span class="nb">all</span> <span class="n">data</span> <span class="o">*/</span>
    <span class="n">memcpy</span><span class="p">(</span><span class="n">ret</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="n">sizeof</span><span class="p">(</span><span class="n">eldoubler_aux_data</span><span class="p">));</span>

    <span class="o">/*</span> <span class="n">Fix</span> <span class="n">up</span> <span class="n">the</span> <span class="n">owned</span> <span class="n">auxdata</span> <span class="n">so</span> <span class="n">we</span> <span class="n">have</span> <span class="n">our</span> <span class="n">own</span> <span class="n">copy</span> <span class="o">*/</span>
    <span class="n">ret</span><span class="o">-&gt;</span><span class="n">funcdata</span> <span class="o">=</span> <span class="n">NPY_AUXDATA_CLONE</span><span class="p">(</span><span class="n">ret</span><span class="o">-&gt;</span><span class="n">funcdata</span><span class="p">);</span>
    <span class="k">if</span> <span class="p">(</span><span class="n">ret</span><span class="o">-&gt;</span><span class="n">funcdata</span> <span class="o">==</span> <span class="n">NULL</span><span class="p">)</span> <span class="p">{</span>
        <span class="n">PyArray_free</span><span class="p">(</span><span class="n">ret</span><span class="p">);</span>
        <span class="k">return</span> <span class="n">NULL</span><span class="p">;</span>
    <span class="p">}</span>

    <span class="k">return</span> <span class="p">(</span><span class="n">NpyAuxData</span> <span class="o">*</span><span class="p">)</span><span class="n">ret</span><span class="p">;</span>
<span class="p">}</span>

<span class="n">NpyAuxData</span> <span class="o">*</span><span class="n">create_element_doubler_aux_data</span><span class="p">(</span>
                            <span class="n">ElementCopier_Func</span> <span class="o">*</span><span class="n">func</span><span class="p">,</span>
                            <span class="n">NpyAuxData</span> <span class="o">*</span><span class="n">funcdata</span><span class="p">)</span>
<span class="p">{</span>
    <span class="n">eldoubler_aux_data</span> <span class="o">*</span><span class="n">ret</span> <span class="o">=</span> <span class="n">PyArray_malloc</span><span class="p">(</span><span class="n">sizeof</span><span class="p">(</span><span class="n">eldoubler_aux_data</span><span class="p">));</span>
    <span class="k">if</span> <span class="p">(</span><span class="n">ret</span> <span class="o">==</span> <span class="n">NULL</span><span class="p">)</span> <span class="p">{</span>
        <span class="n">PyErr_NoMemory</span><span class="p">();</span>
        <span class="k">return</span> <span class="n">NULL</span><span class="p">;</span>
    <span class="p">}</span>
    <span class="n">memset</span><span class="p">(</span><span class="o">&amp;</span><span class="n">ret</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="n">sizeof</span><span class="p">(</span><span class="n">eldoubler_aux_data</span><span class="p">));</span>
    <span class="n">ret</span><span class="o">-&gt;</span><span class="n">base</span><span class="o">-&gt;</span><span class="n">free</span> <span class="o">=</span> <span class="o">&amp;</span><span class="n">free_element_doubler_aux_data</span><span class="p">;</span>
    <span class="n">ret</span><span class="o">-&gt;</span><span class="n">base</span><span class="o">-&gt;</span><span class="n">clone</span> <span class="o">=</span> <span class="o">&amp;</span><span class="n">clone_element_doubler_aux_data</span><span class="p">;</span>
    <span class="n">ret</span><span class="o">-&gt;</span><span class="n">func</span> <span class="o">=</span> <span class="n">func</span><span class="p">;</span>
    <span class="n">ret</span><span class="o">-&gt;</span><span class="n">funcdata</span> <span class="o">=</span> <span class="n">funcdata</span><span class="p">;</span>

    <span class="k">return</span> <span class="p">(</span><span class="n">NpyAuxData</span> <span class="o">*</span><span class="p">)</span><span class="n">ret</span><span class="p">;</span>
<span class="p">}</span>
</pre></div>
</div>
<dl class="type">
<dt id="c.NpyAuxData_FreeFunc">
<code class="sig-name descname">NpyAuxData_FreeFunc</code><a class="headerlink" href="#c.NpyAuxData_FreeFunc" title="Permalink to this definition">¶</a></dt>
<dd><p>The function pointer type for NpyAuxData free functions.</p>
</dd></dl>

<dl class="type">
<dt id="c.NpyAuxData_CloneFunc">
<code class="sig-name descname">NpyAuxData_CloneFunc</code><a class="headerlink" href="#c.NpyAuxData_CloneFunc" title="Permalink to this definition">¶</a></dt>
<dd><p>The function pointer type for NpyAuxData clone functions. These
functions should never set the Python exception on error, because
they may be called from a multi-threaded context.</p>
</dd></dl>

<dl class="function">
<dt id="c.NPY_AUXDATA_FREE">
<code class="sig-name descname">NPY_AUXDATA_FREE</code><span class="sig-paren">(</span>auxdata<span class="sig-paren">)</span><a class="headerlink" href="#c.NPY_AUXDATA_FREE" title="Permalink to this definition">¶</a></dt>
<dd><p>A macro which calls the auxdata’s free function appropriately,
does nothing if auxdata is NULL.</p>
</dd></dl>

<dl class="function">
<dt id="c.NPY_AUXDATA_CLONE">
<code class="sig-name descname">NPY_AUXDATA_CLONE</code><span class="sig-paren">(</span>auxdata<span class="sig-paren">)</span><a class="headerlink" href="#c.NPY_AUXDATA_CLONE" title="Permalink to this definition">¶</a></dt>
<dd><p>A macro which calls the auxdata’s clone function appropriately,
returning a deep copy of the auxiliary data.</p>
</dd></dl>

</div>
<div class="section" id="array-iterators">
<h2>Array Iterators<a class="headerlink" href="#array-iterators" title="Permalink to this headline">¶</a></h2>
<p>As of NumPy 1.6.0, these array iterators are superceded by
the new array iterator, <a class="reference internal" href="iterator.html#c.NpyIter" title="NpyIter"><code class="xref c c-type docutils literal notranslate"><span class="pre">NpyIter</span></code></a>.</p>
<p>An array iterator is a simple way to access the elements of an
N-dimensional array quickly and efficiently. Section <a class="reference external" href="#sec-array-iterator">2</a> provides more description and examples of
this useful approach to looping over an array.</p>
<dl class="function">
<dt id="c.PyArray_IterNew">
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>* <code class="sig-name descname">PyArray_IterNew</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> arr</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_IterNew" title="Permalink to this definition">¶</a></dt>
<dd><p>Return an array iterator object from the array, <em>arr</em>. This is
equivalent to <em>arr</em>. <strong>flat</strong>. The array iterator object makes
it easy to loop over an N-dimensional non-contiguous array in
C-style contiguous fashion.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_IterAllButAxis">
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>* <code class="sig-name descname">PyArray_IterAllButAxis</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> arr</em>, int<em> *axis</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_IterAllButAxis" title="Permalink to this definition">¶</a></dt>
<dd><p>Return an array iterator that will iterate over all axes but the
one provided in <em>*axis</em>. The returned iterator cannot be used
with <a class="reference internal" href="#c.PyArray_ITER_GOTO1D" title="PyArray_ITER_GOTO1D"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_ITER_GOTO1D</span></code></a>. This iterator could be used to
write something similar to what ufuncs do wherein the loop over
the largest axis is done by a separate sub-routine. If <em>*axis</em> is
negative then <em>*axis</em> will be set to the axis having the smallest
stride and that axis will be used.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_BroadcastToShape">
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a> *<code class="sig-name descname">PyArray_BroadcastToShape</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> arr</em>, <a class="reference internal" href="dtype.html#c.npy_intp" title="npy_intp">npy_intp</a><em> *dimensions</em>, int<em> nd</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_BroadcastToShape" title="Permalink to this definition">¶</a></dt>
<dd><p>Return an array iterator that is broadcast to iterate as an array
of the shape provided by <em>dimensions</em> and <em>nd</em>.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArrayIter_Check">
int <code class="sig-name descname">PyArrayIter_Check</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> op</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArrayIter_Check" title="Permalink to this definition">¶</a></dt>
<dd><p>Evaluates true if <em>op</em> is an array iterator (or instance of a
subclass of the array iterator type).</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_ITER_RESET">
void <code class="sig-name descname">PyArray_ITER_RESET</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> iterator</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_ITER_RESET" title="Permalink to this definition">¶</a></dt>
<dd><p>Reset an <em>iterator</em> to the beginning of the array.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_ITER_NEXT">
void <code class="sig-name descname">PyArray_ITER_NEXT</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> iterator</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_ITER_NEXT" title="Permalink to this definition">¶</a></dt>
<dd><p>Incremement the index and the dataptr members of the <em>iterator</em> to
point to the next element of the array. If the array is not
(C-style) contiguous, also increment the N-dimensional coordinates
array.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_ITER_DATA">
void *<code class="sig-name descname">PyArray_ITER_DATA</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> iterator</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_ITER_DATA" title="Permalink to this definition">¶</a></dt>
<dd><p>A pointer to the current element of the array.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_ITER_GOTO">
void <code class="sig-name descname">PyArray_ITER_GOTO</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> iterator</em>, <a class="reference internal" href="dtype.html#c.npy_intp" title="npy_intp">npy_intp</a>*<em> destination</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_ITER_GOTO" title="Permalink to this definition">¶</a></dt>
<dd><p>Set the <em>iterator</em> index, dataptr, and coordinates members to the
location in the array indicated by the N-dimensional c-array,
<em>destination</em>, which must have size at least <em>iterator</em>
-&gt;nd_m1+1.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_ITER_GOTO1D">
<code class="sig-name descname">PyArray_ITER_GOTO1D</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> iterator</em>, <a class="reference internal" href="dtype.html#c.npy_intp" title="npy_intp">npy_intp</a><em> index</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_ITER_GOTO1D" title="Permalink to this definition">¶</a></dt>
<dd><p>Set the <em>iterator</em> index and dataptr to the location in the array
indicated by the integer <em>index</em> which points to an element in the
C-styled flattened array.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_ITER_NOTDONE">
int <code class="sig-name descname">PyArray_ITER_NOTDONE</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> iterator</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_ITER_NOTDONE" title="Permalink to this definition">¶</a></dt>
<dd><p>Evaluates TRUE as long as the iterator has not looped through all of
the elements, otherwise it evaluates FALSE.</p>
</dd></dl>

</div>
<div class="section" id="broadcasting-multi-iterators">
<h2>Broadcasting (multi-iterators)<a class="headerlink" href="#broadcasting-multi-iterators" title="Permalink to this headline">¶</a></h2>
<dl class="function">
<dt id="c.PyArray_MultiIterNew">
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>* <code class="sig-name descname">PyArray_MultiIterNew</code><span class="sig-paren">(</span>int<em> num</em>, ...<span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_MultiIterNew" title="Permalink to this definition">¶</a></dt>
<dd><p>A simplified interface to broadcasting. This function takes the
number of arrays to broadcast and then <em>num</em> extra ( <a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyObject</span> <span class="pre">*</span></code></a>
) arguments. These arguments are converted to arrays and iterators
are created. <a class="reference internal" href="#c.PyArray_Broadcast" title="PyArray_Broadcast"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_Broadcast</span></code></a> is then called on the resulting
multi-iterator object. The resulting, broadcasted mult-iterator
object is then returned. A broadcasted operation can then be
performed using a single loop and using <a class="reference internal" href="#c.PyArray_MultiIter_NEXT" title="PyArray_MultiIter_NEXT"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_MultiIter_NEXT</span></code></a>
(..)</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_MultiIter_RESET">
void <code class="sig-name descname">PyArray_MultiIter_RESET</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> multi</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_MultiIter_RESET" title="Permalink to this definition">¶</a></dt>
<dd><p>Reset all the iterators to the beginning in a multi-iterator
object, <em>multi</em>.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_MultiIter_NEXT">
void <code class="sig-name descname">PyArray_MultiIter_NEXT</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> multi</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_MultiIter_NEXT" title="Permalink to this definition">¶</a></dt>
<dd><p>Advance each iterator in a multi-iterator object, <em>multi</em>, to its
next (broadcasted) element.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_MultiIter_DATA">
void *<code class="sig-name descname">PyArray_MultiIter_DATA</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> multi</em>, int<em> i</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_MultiIter_DATA" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the data-pointer of the <em>i</em> <img class="math" src="../../_images/math/93895e2e935384e36afcc41dd0bdfc48b06a0431.svg" alt="^{\textrm{th}}"/> iterator
in a multi-iterator object.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_MultiIter_NEXTi">
void <code class="sig-name descname">PyArray_MultiIter_NEXTi</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> multi</em>, int<em> i</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_MultiIter_NEXTi" title="Permalink to this definition">¶</a></dt>
<dd><p>Advance the pointer of only the <em>i</em> <img class="math" src="../../_images/math/93895e2e935384e36afcc41dd0bdfc48b06a0431.svg" alt="^{\textrm{th}}"/> iterator.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_MultiIter_GOTO">
void <code class="sig-name descname">PyArray_MultiIter_GOTO</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> multi</em>, <a class="reference internal" href="dtype.html#c.npy_intp" title="npy_intp">npy_intp</a>*<em> destination</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_MultiIter_GOTO" title="Permalink to this definition">¶</a></dt>
<dd><p>Advance each iterator in a multi-iterator object, <em>multi</em>, to the
given <img class="math" src="../../_images/math/3bfb3a64189a14b2704f4610827762d5e3145114.svg" alt="N"/> -dimensional <em>destination</em> where <img class="math" src="../../_images/math/3bfb3a64189a14b2704f4610827762d5e3145114.svg" alt="N"/> is the
number of dimensions in the broadcasted array.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_MultiIter_GOTO1D">
void <code class="sig-name descname">PyArray_MultiIter_GOTO1D</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> multi</em>, <a class="reference internal" href="dtype.html#c.npy_intp" title="npy_intp">npy_intp</a><em> index</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_MultiIter_GOTO1D" title="Permalink to this definition">¶</a></dt>
<dd><p>Advance each iterator in a multi-iterator object, <em>multi</em>, to the
corresponding location of the <em>index</em> into the flattened
broadcasted array.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_MultiIter_NOTDONE">
int <code class="sig-name descname">PyArray_MultiIter_NOTDONE</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> multi</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_MultiIter_NOTDONE" title="Permalink to this definition">¶</a></dt>
<dd><p>Evaluates TRUE as long as the multi-iterator has not looped
through all of the elements (of the broadcasted result), otherwise
it evaluates FALSE.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_Broadcast">
int <code class="sig-name descname">PyArray_Broadcast</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayMultiIterObject" title="PyArrayMultiIterObject">PyArrayMultiIterObject</a>*<em> mit</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_Broadcast" title="Permalink to this definition">¶</a></dt>
<dd><p>This function encapsulates the broadcasting rules. The <em>mit</em>
container should already contain iterators for all the arrays that
need to be broadcast. On return, these iterators will be adjusted
so that iteration over each simultaneously will accomplish the
broadcasting. A negative number is returned if an error occurs.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_RemoveSmallest">
int <code class="sig-name descname">PyArray_RemoveSmallest</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayMultiIterObject" title="PyArrayMultiIterObject">PyArrayMultiIterObject</a>*<em> mit</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_RemoveSmallest" title="Permalink to this definition">¶</a></dt>
<dd><p>This function takes a multi-iterator object that has been
previously “broadcasted,” finds the dimension with the smallest
“sum of strides” in the broadcasted result and adapts all the
iterators so as not to iterate over that dimension (by effectively
making them of length-1 in that dimension). The corresponding
dimension is returned unless <em>mit</em> -&gt;nd is 0, then -1 is
returned. This function is useful for constructing ufunc-like
routines that broadcast their inputs correctly and then call a
strided 1-d version of the routine as the inner-loop.  This 1-d
version is usually optimized for speed and for this reason the
loop should be performed over the axis that won’t require large
stride jumps.</p>
</dd></dl>

</div>
<div class="section" id="neighborhood-iterator">
<h2>Neighborhood iterator<a class="headerlink" href="#neighborhood-iterator" title="Permalink to this headline">¶</a></h2>
<div class="versionadded">
<p><span class="versionmodified added">New in version 1.4.0.</span></p>
</div>
<p>Neighborhood iterators are subclasses of the iterator object, and can be used
to iter over a neighborhood of a point. For example, you may want to iterate
over every voxel of a 3d image, and for every such voxel, iterate over an
hypercube. Neighborhood iterator automatically handle boundaries, thus making
this kind of code much easier to write than manual boundaries handling, at the
cost of a slight overhead.</p>
<dl class="function">
<dt id="c.PyArray_NeighborhoodIterNew">
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>* <code class="sig-name descname">PyArray_NeighborhoodIterNew</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayIterObject" title="PyArrayIterObject">PyArrayIterObject</a>*<em> iter</em>, <a class="reference internal" href="dtype.html#c.npy_intp" title="npy_intp">npy_intp</a><em> bounds</em>, int<em> mode</em>, <a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> fill_value</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_NeighborhoodIterNew" title="Permalink to this definition">¶</a></dt>
<dd><p>This function creates a new neighborhood iterator from an existing
iterator.  The neighborhood will be computed relatively to the position
currently pointed by <em>iter</em>, the bounds define the shape of the
neighborhood iterator, and the mode argument the boundaries handling mode.</p>
<p>The <em>bounds</em> argument is expected to be a (2 * iter-&gt;ao-&gt;nd) arrays, such
as the range bound[2*i]-&gt;bounds[2*i+1] defines the range where to walk for
dimension i (both bounds are included in the walked coordinates). The
bounds should be ordered for each dimension (bounds[2*i] &lt;= bounds[2*i+1]).</p>
<p>The mode should be one of:</p>
<dl class="macro">
<dt id="c.NPY_NEIGHBORHOOD_ITER_ZERO_PADDING">
<code class="sig-name descname">NPY_NEIGHBORHOOD_ITER_ZERO_PADDING</code><a class="headerlink" href="#c.NPY_NEIGHBORHOOD_ITER_ZERO_PADDING" title="Permalink to this definition">¶</a></dt>
<dd><p>Zero padding. Outside bounds values will be 0.</p>
</dd></dl>

<dl class="macro">
<dt id="c.NPY_NEIGHBORHOOD_ITER_ONE_PADDING">
<code class="sig-name descname">NPY_NEIGHBORHOOD_ITER_ONE_PADDING</code><a class="headerlink" href="#c.NPY_NEIGHBORHOOD_ITER_ONE_PADDING" title="Permalink to this definition">¶</a></dt>
<dd><p>One padding, Outside bounds values will be 1.</p>
</dd></dl>

<dl class="macro">
<dt id="c.NPY_NEIGHBORHOOD_ITER_CONSTANT_PADDING">
<code class="sig-name descname">NPY_NEIGHBORHOOD_ITER_CONSTANT_PADDING</code><a class="headerlink" href="#c.NPY_NEIGHBORHOOD_ITER_CONSTANT_PADDING" title="Permalink to this definition">¶</a></dt>
<dd><p>Constant padding. Outside bounds values will be the
same as the first item in fill_value.</p>
</dd></dl>

<dl class="macro">
<dt id="c.NPY_NEIGHBORHOOD_ITER_MIRROR_PADDING">
<code class="sig-name descname">NPY_NEIGHBORHOOD_ITER_MIRROR_PADDING</code><a class="headerlink" href="#c.NPY_NEIGHBORHOOD_ITER_MIRROR_PADDING" title="Permalink to this definition">¶</a></dt>
<dd><p>Mirror padding. Outside bounds values will be as if the
array items were mirrored. For example, for the array [1, 2, 3, 4],
x[-2] will be 2, x[-2] will be 1, x[4] will be 4, x[5] will be 1,
etc…</p>
</dd></dl>

<dl class="macro">
<dt id="c.NPY_NEIGHBORHOOD_ITER_CIRCULAR_PADDING">
<code class="sig-name descname">NPY_NEIGHBORHOOD_ITER_CIRCULAR_PADDING</code><a class="headerlink" href="#c.NPY_NEIGHBORHOOD_ITER_CIRCULAR_PADDING" title="Permalink to this definition">¶</a></dt>
<dd><p>Circular padding. Outside bounds values will be as if the array
was repeated. For example, for the array [1, 2, 3, 4], x[-2] will
be 3, x[-2] will be 4, x[4] will be 1, x[5] will be 2, etc…</p>
</dd></dl>

<p>If the mode is constant filling (<em class="xref py py-obj">NPY_NEIGHBORHOOD_ITER_CONSTANT_PADDING</em>),
fill_value should point to an array object which holds the filling value
(the first item will be the filling value if the array contains more than
one item). For other cases, fill_value may be NULL.</p>
<ul class="simple">
<li><p>The iterator holds a reference to iter</p></li>
<li><p>Return NULL on failure (in which case the reference count of iter is not
changed)</p></li>
<li><p>iter itself can be a Neighborhood iterator: this can be useful for .e.g
automatic boundaries handling</p></li>
<li><p>the object returned by this function should be safe to use as a normal
iterator</p></li>
<li><p>If the position of iter is changed, any subsequent call to
PyArrayNeighborhoodIter_Next is undefined behavior, and
PyArrayNeighborhoodIter_Reset must be called.</p></li>
</ul>
<div class="highlight-c notranslate"><div class="highlight"><pre><span></span><span class="n">PyArrayIterObject</span> <span class="o">*</span><span class="n">iter</span><span class="p">;</span>
<span class="n">PyArrayNeighborhoodIterObject</span> <span class="o">*</span><span class="n">neigh_iter</span><span class="p">;</span>
<span class="n">iter</span> <span class="o">=</span> <span class="n">PyArray_IterNew</span><span class="p">(</span><span class="n">x</span><span class="p">);</span>

<span class="cm">/*For a 3x3 kernel */</span>
<span class="n">bounds</span> <span class="o">=</span> <span class="p">{</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">};</span>
<span class="n">neigh_iter</span> <span class="o">=</span> <span class="p">(</span><span class="n">PyArrayNeighborhoodIterObject</span><span class="o">*</span><span class="p">)</span><span class="n">PyArrayNeighborhoodIter_New</span><span class="p">(</span>
     <span class="n">iter</span><span class="p">,</span> <span class="n">bounds</span><span class="p">,</span> <span class="n">NPY_NEIGHBORHOOD_ITER_ZERO_PADDING</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span>

<span class="k">for</span><span class="p">(</span><span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="n">iter</span><span class="o">-&gt;</span><span class="n">size</span><span class="p">;</span> <span class="o">++</span><span class="n">i</span><span class="p">)</span> <span class="p">{</span>
     <span class="k">for</span> <span class="p">(</span><span class="n">j</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">j</span> <span class="o">&lt;</span> <span class="n">neigh_iter</span><span class="o">-&gt;</span><span class="n">size</span><span class="p">;</span> <span class="o">++</span><span class="n">j</span><span class="p">)</span> <span class="p">{</span>
             <span class="cm">/* Walk around the item currently pointed by iter-&gt;dataptr */</span>
             <span class="n">PyArrayNeighborhoodIter_Next</span><span class="p">(</span><span class="n">neigh_iter</span><span class="p">);</span>
     <span class="p">}</span>

     <span class="cm">/* Move to the next point of iter */</span>
     <span class="n">PyArrayIter_Next</span><span class="p">(</span><span class="n">iter</span><span class="p">);</span>
     <span class="n">PyArrayNeighborhoodIter_Reset</span><span class="p">(</span><span class="n">neigh_iter</span><span class="p">);</span>
<span class="p">}</span>
</pre></div>
</div>
</dd></dl>

<dl class="function">
<dt id="c.PyArrayNeighborhoodIter_Reset">
int <code class="sig-name descname">PyArrayNeighborhoodIter_Reset</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayNeighborhoodIterObject" title="PyArrayNeighborhoodIterObject">PyArrayNeighborhoodIterObject</a>*<em> iter</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArrayNeighborhoodIter_Reset" title="Permalink to this definition">¶</a></dt>
<dd><p>Reset the iterator position to the first point of the neighborhood. This
should be called whenever the iter argument given at
PyArray_NeighborhoodIterObject is changed (see example)</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArrayNeighborhoodIter_Next">
int <code class="sig-name descname">PyArrayNeighborhoodIter_Next</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayNeighborhoodIterObject" title="PyArrayNeighborhoodIterObject">PyArrayNeighborhoodIterObject</a>*<em> iter</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArrayNeighborhoodIter_Next" title="Permalink to this definition">¶</a></dt>
<dd><p>After this call, iter-&gt;dataptr points to the next point of the
neighborhood. Calling this function after every point of the
neighborhood has been visited is undefined.</p>
</dd></dl>

</div>
<div class="section" id="array-scalars">
<h2>Array Scalars<a class="headerlink" href="#array-scalars" title="Permalink to this headline">¶</a></h2>
<dl class="function">
<dt id="c.PyArray_Return">
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>* <code class="sig-name descname">PyArray_Return</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> arr</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_Return" title="Permalink to this definition">¶</a></dt>
<dd><p>This function steals a reference to <em>arr</em>.</p>
<p>This function checks to see if <em>arr</em> is a 0-dimensional array and,
if so, returns the appropriate array scalar. It should be used
whenever 0-dimensional arrays could be returned to Python.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_Scalar">
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>* <code class="sig-name descname">PyArray_Scalar</code><span class="sig-paren">(</span>void*<em> data</em>, <a class="reference internal" href="types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>*<em> dtype</em>, <a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> itemsize</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_Scalar" title="Permalink to this definition">¶</a></dt>
<dd><p>Return an array scalar object of the given enumerated <em>typenum</em>
and <em>itemsize</em> by <strong>copying</strong> from memory pointed to by <em>data</em>
. If <em>swap</em> is nonzero then this function will byteswap the data
if appropriate to the data-type because array scalars are always
in correct machine-byte order.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_ToScalar">
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>* <code class="sig-name descname">PyArray_ToScalar</code><span class="sig-paren">(</span>void*<em> data</em>, <a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> arr</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_ToScalar" title="Permalink to this definition">¶</a></dt>
<dd><p>Return an array scalar object of the type and itemsize indicated
by the array object <em>arr</em> copied from the memory pointed to by
<em>data</em> and swapping if the data in <em>arr</em> is not in machine
byte-order.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_FromScalar">
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>* <code class="sig-name descname">PyArray_FromScalar</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> scalar</em>, <a class="reference internal" href="types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>*<em> outcode</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_FromScalar" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a 0-dimensional array of type determined by <em>outcode</em> from
<em>scalar</em> which should be an array-scalar object. If <em>outcode</em> is
NULL, then the type is determined from <em>scalar</em>.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_ScalarAsCtype">
void <code class="sig-name descname">PyArray_ScalarAsCtype</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> scalar</em>, void*<em> ctypeptr</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_ScalarAsCtype" title="Permalink to this definition">¶</a></dt>
<dd><p>Return in <em>ctypeptr</em> a pointer to the actual value in an array
scalar. There is no error checking so <em>scalar</em> must be an
array-scalar object, and ctypeptr must have enough space to hold
the correct type. For flexible-sized types, a pointer to the data
is copied into the memory of <em>ctypeptr</em>, for all other types, the
actual data is copied into the address pointed to by <em>ctypeptr</em>.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_CastScalarToCtype">
void <code class="sig-name descname">PyArray_CastScalarToCtype</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> scalar</em>, void*<em> ctypeptr</em>, <a class="reference internal" href="types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>*<em> outcode</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_CastScalarToCtype" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the data (cast to the data type indicated by <em>outcode</em>)
from the array-scalar, <em>scalar</em>, into the memory pointed to by
<em>ctypeptr</em> (which must be large enough to handle the incoming
memory).</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_TypeObjectFromType">
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>* <code class="sig-name descname">PyArray_TypeObjectFromType</code><span class="sig-paren">(</span>int<em> type</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_TypeObjectFromType" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns a scalar type-object from a type-number, <em>type</em>
. Equivalent to <a class="reference internal" href="#c.PyArray_DescrFromType" title="PyArray_DescrFromType"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_DescrFromType</span></code></a> (<em>type</em>)-&gt;typeobj
except for reference counting and error-checking. Returns a new
reference to the typeobject on success or <code class="docutils literal notranslate"><span class="pre">NULL</span></code> on failure.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_ScalarKind">
<a class="reference internal" href="#c.NPY_SCALARKIND" title="NPY_SCALARKIND">NPY_SCALARKIND</a> <code class="sig-name descname">PyArray_ScalarKind</code><span class="sig-paren">(</span>int<em> typenum</em>, <a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>**<em> arr</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_ScalarKind" title="Permalink to this definition">¶</a></dt>
<dd><p>See the function <a class="reference internal" href="#c.PyArray_MinScalarType" title="PyArray_MinScalarType"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_MinScalarType</span></code></a> for an alternative
mechanism introduced in NumPy 1.6.0.</p>
<p>Return the kind of scalar represented by <em>typenum</em> and the array
in <em>*arr</em> (if <em>arr</em> is not <code class="docutils literal notranslate"><span class="pre">NULL</span></code> ). The array is assumed to be
rank-0 and only used if <em>typenum</em> represents a signed integer. If
<em>arr</em> is not <code class="docutils literal notranslate"><span class="pre">NULL</span></code> and the first element is negative then
<a class="reference internal" href="#c.NPY_INTNEG_SCALAR" title="NPY_INTNEG_SCALAR"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_INTNEG_SCALAR</span></code></a> is returned, otherwise
<a class="reference internal" href="#c.NPY_INTPOS_SCALAR" title="NPY_INTPOS_SCALAR"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_INTPOS_SCALAR</span></code></a> is returned. The possible return values
are the enumerated values in <a class="reference internal" href="#c.NPY_SCALARKIND" title="NPY_SCALARKIND"><code class="xref c c-type docutils literal notranslate"><span class="pre">NPY_SCALARKIND</span></code></a>.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_CanCoerceScalar">
int <code class="sig-name descname">PyArray_CanCoerceScalar</code><span class="sig-paren">(</span>char<em> thistype</em>, char<em> neededtype</em>, <a class="reference internal" href="#c.NPY_SCALARKIND" title="NPY_SCALARKIND">NPY_SCALARKIND</a><em> scalar</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_CanCoerceScalar" title="Permalink to this definition">¶</a></dt>
<dd><p>See the function <a class="reference internal" href="#c.PyArray_ResultType" title="PyArray_ResultType"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_ResultType</span></code></a> for details of
NumPy type promotion, updated in NumPy 1.6.0.</p>
<p>Implements the rules for scalar coercion. Scalars are only
silently coerced from thistype to neededtype if this function
returns nonzero.  If scalar is <a class="reference internal" href="#c.NPY_NOSCALAR" title="NPY_NOSCALAR"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_NOSCALAR</span></code></a>, then this
function is equivalent to <a class="reference internal" href="#c.PyArray_CanCastSafely" title="PyArray_CanCastSafely"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_CanCastSafely</span></code></a>. The rule is
that scalars of the same KIND can be coerced into arrays of the
same KIND. This rule means that high-precision scalars will never
cause low-precision arrays of the same KIND to be upcast.</p>
</dd></dl>

</div>
<div class="section" id="data-type-descriptors">
<h2>Data-type descriptors<a class="headerlink" href="#data-type-descriptors" title="Permalink to this headline">¶</a></h2>
<div class="admonition warning">
<p class="admonition-title">Warning</p>
<p>Data-type objects must be reference counted so be aware of the
action on the data-type reference of different C-API calls. The
standard rule is that when a data-type object is returned it is a
new reference.  Functions that take <a class="reference internal" href="types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyArray_Descr</span> <span class="pre">*</span></code></a> objects and
return arrays steal references to the data-type their inputs
unless otherwise noted. Therefore, you must own a reference to any
data-type object used as input to such a function.</p>
</div>
<dl class="function">
<dt id="c.PyArray_DescrCheck">
int <code class="sig-name descname">PyArray_DescrCheck</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> obj</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_DescrCheck" title="Permalink to this definition">¶</a></dt>
<dd><p>Evaluates as true if <em>obj</em> is a data-type object ( <a class="reference internal" href="types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyArray_Descr</span> <span class="pre">*</span></code></a> ).</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_DescrNew">
<a class="reference internal" href="types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>* <code class="sig-name descname">PyArray_DescrNew</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>*<em> obj</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_DescrNew" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a new data-type object copied from <em>obj</em> (the fields
reference is just updated so that the new object points to the
same fields dictionary if any).</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_DescrNewFromType">
<a class="reference internal" href="types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>* <code class="sig-name descname">PyArray_DescrNewFromType</code><span class="sig-paren">(</span>int<em> typenum</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_DescrNewFromType" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a new data-type object from the built-in (or
user-registered) data-type indicated by <em>typenum</em>. All builtin
types should not have any of their fields changed. This creates a
new copy of the <a class="reference internal" href="types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyArray_Descr</span></code></a> structure so that you can fill
it in as appropriate. This function is especially needed for
flexible data-types which need to have a new elsize member in
order to be meaningful in array construction.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_DescrNewByteorder">
<a class="reference internal" href="types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>* <code class="sig-name descname">PyArray_DescrNewByteorder</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>*<em> obj</em>, char<em> newendian</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_DescrNewByteorder" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a new data-type object with the byteorder set according to
<em>newendian</em>. All referenced data-type objects (in subdescr and
fields members of the data-type object) are also changed
(recursively). If a byteorder of <code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_IGNORE</span></code> is encountered it
is left alone. If newendian is <code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_SWAP</span></code>, then all byte-orders
are swapped. Other valid newendian values are <code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_NATIVE</span></code>,
<code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_LITTLE</span></code>, and <code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_BIG</span></code> which all cause the returned
data-typed descriptor (and all it’s
referenced data-type descriptors) to have the corresponding byte-
order.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_DescrFromObject">
<a class="reference internal" href="types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>* <code class="sig-name descname">PyArray_DescrFromObject</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> op</em>, <a class="reference internal" href="types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>*<em> mintype</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_DescrFromObject" title="Permalink to this definition">¶</a></dt>
<dd><p>Determine an appropriate data-type object from the object <em>op</em>
(which should be a “nested” sequence object) and the minimum
data-type descriptor mintype (which can be <code class="docutils literal notranslate"><span class="pre">NULL</span></code> ). Similar in
behavior to array(<em>op</em>).dtype. Don’t confuse this function with
<a class="reference internal" href="#c.PyArray_DescrConverter" title="PyArray_DescrConverter"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_DescrConverter</span></code></a>. This function essentially looks at
all the objects in the (nested) sequence and determines the
data-type from the elements it finds.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_DescrFromScalar">
<a class="reference internal" href="types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>* <code class="sig-name descname">PyArray_DescrFromScalar</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> scalar</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_DescrFromScalar" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a data-type object from an array-scalar object. No checking
is done to be sure that <em>scalar</em> is an array scalar. If no
suitable data-type can be determined, then a data-type of
<a class="reference internal" href="dtype.html#c.NPY_OBJECT" title="NPY_OBJECT"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_OBJECT</span></code></a> is returned by default.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_DescrFromType">
<a class="reference internal" href="types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>* <code class="sig-name descname">PyArray_DescrFromType</code><span class="sig-paren">(</span>int<em> typenum</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_DescrFromType" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns a data-type object corresponding to <em>typenum</em>. The
<em>typenum</em> can be one of the enumerated types, a character code for
one of the enumerated types, or a user-defined type. If you want to use a
flexible size array, then you need to <code class="docutils literal notranslate"><span class="pre">flexible</span> <span class="pre">typenum</span></code> and set the
results <code class="docutils literal notranslate"><span class="pre">elsize</span></code> parameter to the desired size. The typenum is one of the
<a class="reference internal" href="dtype.html#c.NPY_TYPES" title="NPY_TYPES"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_TYPES</span></code></a>.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_DescrConverter">
int <code class="sig-name descname">PyArray_DescrConverter</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> obj</em>, <a class="reference internal" href="types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>**<em> dtype</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_DescrConverter" title="Permalink to this definition">¶</a></dt>
<dd><p>Convert any compatible Python object, <em>obj</em>, to a data-type object
in <em>dtype</em>. A large number of Python objects can be converted to
data-type objects. See <a class="reference internal" href="../arrays.dtypes.html#arrays-dtypes"><span class="std std-ref">Data type objects (dtype)</span></a> for a complete
description. This version of the converter converts None objects
to a <a class="reference internal" href="dtype.html#c.NPY_DEFAULT_TYPE" title="NPY_DEFAULT_TYPE"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_DEFAULT_TYPE</span></code></a> data-type object. This function can
be used with the “O&amp;” character code in <a class="reference external" href="https://docs.python.org/dev/c-api/arg.html#c.PyArg_ParseTuple" title="(in Python v3.9)"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArg_ParseTuple</span></code></a>
processing.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_DescrConverter2">
int <code class="sig-name descname">PyArray_DescrConverter2</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> obj</em>, <a class="reference internal" href="types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>**<em> dtype</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_DescrConverter2" title="Permalink to this definition">¶</a></dt>
<dd><p>Convert any compatible Python object, <em>obj</em>, to a data-type
object in <em>dtype</em>. This version of the converter converts None
objects so that the returned data-type is <code class="docutils literal notranslate"><span class="pre">NULL</span></code>. This function
can also be used with the “O&amp;” character in PyArg_ParseTuple
processing.</p>
</dd></dl>

<dl class="function">
<dt id="c.Pyarray_DescrAlignConverter">
int <code class="sig-name descname">Pyarray_DescrAlignConverter</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> obj</em>, <a class="reference internal" href="types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>**<em> dtype</em><span class="sig-paren">)</span><a class="headerlink" href="#c.Pyarray_DescrAlignConverter" title="Permalink to this definition">¶</a></dt>
<dd><p>Like <a class="reference internal" href="#c.PyArray_DescrConverter" title="PyArray_DescrConverter"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_DescrConverter</span></code></a> except it aligns C-struct-like
objects on word-boundaries as the compiler would.</p>
</dd></dl>

<dl class="function">
<dt id="c.Pyarray_DescrAlignConverter2">
int <code class="sig-name descname">Pyarray_DescrAlignConverter2</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> obj</em>, <a class="reference internal" href="types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a>**<em> dtype</em><span class="sig-paren">)</span><a class="headerlink" href="#c.Pyarray_DescrAlignConverter2" title="Permalink to this definition">¶</a></dt>
<dd><p>Like <a class="reference internal" href="#c.PyArray_DescrConverter2" title="PyArray_DescrConverter2"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_DescrConverter2</span></code></a> except it aligns C-struct-like
objects on word-boundaries as the compiler would.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_FieldNames">
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a> *<code class="sig-name descname">PyArray_FieldNames</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> dict</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_FieldNames" title="Permalink to this definition">¶</a></dt>
<dd><p>Take the fields dictionary, <em>dict</em>, such as the one attached to a
data-type object and construct an ordered-list of field names such
as is stored in the names field of the <a class="reference internal" href="types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyArray_Descr</span></code></a> object.</p>
</dd></dl>

</div>
<div class="section" id="conversion-utilities">
<h2>Conversion Utilities<a class="headerlink" href="#conversion-utilities" title="Permalink to this headline">¶</a></h2>
<div class="section" id="for-use-with-pyarg-parsetuple">
<h3>For use with <a class="reference external" href="https://docs.python.org/dev/c-api/arg.html#c.PyArg_ParseTuple" title="(in Python v3.9)"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArg_ParseTuple</span></code></a><a class="headerlink" href="#for-use-with-pyarg-parsetuple" title="Permalink to this headline">¶</a></h3>
<p>All of these functions can be used in <a class="reference external" href="https://docs.python.org/dev/c-api/arg.html#c.PyArg_ParseTuple" title="(in Python v3.9)"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArg_ParseTuple</span></code></a> (…) with
the “O&amp;” format specifier to automatically convert any Python object
to the required C-object. All of these functions return
<a class="reference internal" href="#c.NPY_SUCCEED" title="NPY_SUCCEED"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_SUCCEED</span></code></a> if successful and <a class="reference internal" href="#c.NPY_FAIL" title="NPY_FAIL"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_FAIL</span></code></a> if not. The first
argument to all of these function is a Python object. The second
argument is the <strong>address</strong> of the C-type to convert the Python object
to.</p>
<div class="admonition warning">
<p class="admonition-title">Warning</p>
<p>Be sure to understand what steps you should take to manage the
memory when using these conversion functions. These functions can
require freeing memory, and/or altering the reference counts of
specific objects based on your use.</p>
</div>
<dl class="function">
<dt id="c.PyArray_Converter">
int <code class="sig-name descname">PyArray_Converter</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> obj</em>, <a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>**<em> address</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_Converter" title="Permalink to this definition">¶</a></dt>
<dd><p>Convert any Python object to a <a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyArrayObject</span></code></a>. If
<a class="reference internal" href="#c.PyArray_Check" title="PyArray_Check"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_Check</span></code></a> (<em>obj</em>) is TRUE then its reference count is
incremented and a reference placed in <em>address</em>. If <em>obj</em> is not
an array, then convert it to an array using <a class="reference internal" href="#c.PyArray_FromAny" title="PyArray_FromAny"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_FromAny</span></code></a>
. No matter what is returned, you must DECREF the object returned
by this routine in <em>address</em> when you are done with it.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_OutputConverter">
int <code class="sig-name descname">PyArray_OutputConverter</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> obj</em>, <a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>**<em> address</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_OutputConverter" title="Permalink to this definition">¶</a></dt>
<dd><p>This is a default converter for output arrays given to
functions. If <em>obj</em> is <a class="reference external" href="https://docs.python.org/dev/c-api/none.html#c.Py_None" title="(in Python v3.9)"><code class="xref c c-data docutils literal notranslate"><span class="pre">Py_None</span></code></a> or <code class="docutils literal notranslate"><span class="pre">NULL</span></code>, then <em>*address</em>
will be <code class="docutils literal notranslate"><span class="pre">NULL</span></code> but the call will succeed. If <a class="reference internal" href="#c.PyArray_Check" title="PyArray_Check"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_Check</span></code></a> (
<em>obj</em>) is TRUE then it is returned in <em>*address</em> without
incrementing its reference count.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_IntpConverter">
int <code class="sig-name descname">PyArray_IntpConverter</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> obj</em>, <a class="reference internal" href="types-and-structures.html#c.PyArray_Dims" title="PyArray_Dims">PyArray_Dims</a>*<em> seq</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_IntpConverter" title="Permalink to this definition">¶</a></dt>
<dd><p>Convert any Python sequence, <em>obj</em>, smaller than <a class="reference internal" href="#c.NPY_MAXDIMS" title="NPY_MAXDIMS"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_MAXDIMS</span></code></a>
to a C-array of <a class="reference internal" href="dtype.html#c.npy_intp" title="npy_intp"><code class="xref c c-type docutils literal notranslate"><span class="pre">npy_intp</span></code></a>. The Python object could also be a
single number. The <em>seq</em> variable is a pointer to a structure with
members ptr and len. On successful return, <em>seq</em> -&gt;ptr contains a
pointer to memory that must be freed, by calling <a class="reference internal" href="#c.PyDimMem_FREE" title="PyDimMem_FREE"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyDimMem_FREE</span></code></a>,
to avoid a memory leak. The restriction on memory size allows this
converter to be conveniently used for sequences intended to be
interpreted as array shapes.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_BufferConverter">
int <code class="sig-name descname">PyArray_BufferConverter</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> obj</em>, <a class="reference internal" href="types-and-structures.html#c.PyArray_Chunk" title="PyArray_Chunk">PyArray_Chunk</a>*<em> buf</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_BufferConverter" title="Permalink to this definition">¶</a></dt>
<dd><p>Convert any Python object, <em>obj</em>, with a (single-segment) buffer
interface to a variable with members that detail the object’s use
of its chunk of memory. The <em>buf</em> variable is a pointer to a
structure with base, ptr, len, and flags members. The
<a class="reference internal" href="types-and-structures.html#c.PyArray_Chunk" title="PyArray_Chunk"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyArray_Chunk</span></code></a> structure is binary compatible with the
Python’s buffer object (through its len member on 32-bit platforms
and its ptr member on 64-bit platforms or in Python 2.5). On
return, the base member is set to <em>obj</em> (or its base if <em>obj</em> is
already a buffer object pointing to another object). If you need
to hold on to the memory be sure to INCREF the base member. The
chunk of memory is pointed to by <em>buf</em> -&gt;ptr member and has length
<em>buf</em> -&gt;len. The flags member of <em>buf</em> is <code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_BEHAVED_RO</span></code> with
the <a class="reference internal" href="#c.NPY_ARRAY_WRITEABLE" title="NPY_ARRAY_WRITEABLE"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_WRITEABLE</span></code></a> flag set if <em>obj</em> has a writeable buffer
interface.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_AxisConverter">
int <code class="sig-name descname">PyArray_AxisConverter</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a> *<em> obj</em>, int*<em> axis</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_AxisConverter" title="Permalink to this definition">¶</a></dt>
<dd><p>Convert a Python object, <em>obj</em>, representing an axis argument to
the proper value for passing to the functions that take an integer
axis. Specifically, if <em>obj</em> is None, <em>axis</em> is set to
<a class="reference internal" href="#c.NPY_MAXDIMS" title="NPY_MAXDIMS"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_MAXDIMS</span></code></a> which is interpreted correctly by the C-API
functions that take axis arguments.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_BoolConverter">
int <code class="sig-name descname">PyArray_BoolConverter</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> obj</em>, Bool*<em> value</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_BoolConverter" title="Permalink to this definition">¶</a></dt>
<dd><p>Convert any Python object, <em>obj</em>, to <a class="reference internal" href="#c.NPY_TRUE" title="NPY_TRUE"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_TRUE</span></code></a> or
<a class="reference internal" href="#c.NPY_FALSE" title="NPY_FALSE"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_FALSE</span></code></a>, and place the result in <em>value</em>.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_ByteorderConverter">
int <code class="sig-name descname">PyArray_ByteorderConverter</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> obj</em>, char*<em> endian</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_ByteorderConverter" title="Permalink to this definition">¶</a></dt>
<dd><p>Convert Python strings into the corresponding byte-order
character:
‘&gt;’, ‘&lt;’, ‘s’, ‘=’, or ‘|’.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_SortkindConverter">
int <code class="sig-name descname">PyArray_SortkindConverter</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> obj</em>, <a class="reference internal" href="#c.NPY_SORTKIND" title="NPY_SORTKIND">NPY_SORTKIND</a>*<em> sort</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_SortkindConverter" title="Permalink to this definition">¶</a></dt>
<dd><p>Convert Python strings into one of <a class="reference internal" href="#c.NPY_QUICKSORT" title="NPY_QUICKSORT"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_QUICKSORT</span></code></a> (starts
with ‘q’ or ‘Q’), <a class="reference internal" href="#c.NPY_HEAPSORT" title="NPY_HEAPSORT"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_HEAPSORT</span></code></a> (starts with ‘h’ or ‘H’),
<a class="reference internal" href="#c.NPY_MERGESORT" title="NPY_MERGESORT"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_MERGESORT</span></code></a> (starts with ‘m’ or ‘M’) or <a class="reference internal" href="#c.NPY_STABLESORT" title="NPY_STABLESORT"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_STABLESORT</span></code></a>
(starts with ‘t’ or ‘T’). <a class="reference internal" href="#c.NPY_MERGESORT" title="NPY_MERGESORT"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_MERGESORT</span></code></a> and <a class="reference internal" href="#c.NPY_STABLESORT" title="NPY_STABLESORT"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_STABLESORT</span></code></a>
are aliased to each other for backwards compatibility and may refer to one
of several stable sorting algorithms depending on the data type.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_SearchsideConverter">
int <code class="sig-name descname">PyArray_SearchsideConverter</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> obj</em>, NPY_SEARCHSIDE*<em> side</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_SearchsideConverter" title="Permalink to this definition">¶</a></dt>
<dd><p>Convert Python strings into one of <code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_SEARCHLEFT</span></code> (starts with ‘l’
or ‘L’), or <code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_SEARCHRIGHT</span></code> (starts with ‘r’ or ‘R’).</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_OrderConverter">
int <code class="sig-name descname">PyArray_OrderConverter</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> obj</em>, <a class="reference internal" href="#c.NPY_ORDER" title="NPY_ORDER">NPY_ORDER</a>*<em> order</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_OrderConverter" title="Permalink to this definition">¶</a></dt>
<dd><p>Convert the Python strings ‘C’, ‘F’, ‘A’, and ‘K’ into the <a class="reference internal" href="#c.NPY_ORDER" title="NPY_ORDER"><code class="xref c c-type docutils literal notranslate"><span class="pre">NPY_ORDER</span></code></a>
enumeration <a class="reference internal" href="#c.NPY_CORDER" title="NPY_CORDER"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_CORDER</span></code></a>, <a class="reference internal" href="#c.NPY_FORTRANORDER" title="NPY_FORTRANORDER"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_FORTRANORDER</span></code></a>,
<a class="reference internal" href="#c.NPY_ANYORDER" title="NPY_ANYORDER"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ANYORDER</span></code></a>, and <a class="reference internal" href="#c.NPY_KEEPORDER" title="NPY_KEEPORDER"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_KEEPORDER</span></code></a>.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_CastingConverter">
int <code class="sig-name descname">PyArray_CastingConverter</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> obj</em>, <a class="reference internal" href="#c.NPY_CASTING" title="NPY_CASTING">NPY_CASTING</a>*<em> casting</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_CastingConverter" title="Permalink to this definition">¶</a></dt>
<dd><p>Convert the Python strings ‘no’, ‘equiv’, ‘safe’, ‘same_kind’, and
‘unsafe’ into the <a class="reference internal" href="#c.NPY_CASTING" title="NPY_CASTING"><code class="xref c c-type docutils literal notranslate"><span class="pre">NPY_CASTING</span></code></a> enumeration <a class="reference internal" href="#c.NPY_NO_CASTING" title="NPY_NO_CASTING"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_NO_CASTING</span></code></a>,
<a class="reference internal" href="#c.NPY_EQUIV_CASTING" title="NPY_EQUIV_CASTING"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_EQUIV_CASTING</span></code></a>, <a class="reference internal" href="#c.NPY_SAFE_CASTING" title="NPY_SAFE_CASTING"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_SAFE_CASTING</span></code></a>,
<a class="reference internal" href="#c.NPY_SAME_KIND_CASTING" title="NPY_SAME_KIND_CASTING"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_SAME_KIND_CASTING</span></code></a>, and <a class="reference internal" href="#c.NPY_UNSAFE_CASTING" title="NPY_UNSAFE_CASTING"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_UNSAFE_CASTING</span></code></a>.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_ClipmodeConverter">
int <code class="sig-name descname">PyArray_ClipmodeConverter</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> object</em>, <a class="reference internal" href="#c.NPY_CLIPMODE" title="NPY_CLIPMODE">NPY_CLIPMODE</a>*<em> val</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_ClipmodeConverter" title="Permalink to this definition">¶</a></dt>
<dd><p>Convert the Python strings ‘clip’, ‘wrap’, and ‘raise’ into the
<a class="reference internal" href="#c.NPY_CLIPMODE" title="NPY_CLIPMODE"><code class="xref c c-type docutils literal notranslate"><span class="pre">NPY_CLIPMODE</span></code></a> enumeration <a class="reference internal" href="#c.NPY_CLIP" title="NPY_CLIP"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_CLIP</span></code></a>, <a class="reference internal" href="#c.NPY_WRAP" title="NPY_WRAP"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_WRAP</span></code></a>,
and <a class="reference internal" href="#c.NPY_RAISE" title="NPY_RAISE"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_RAISE</span></code></a>.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_ConvertClipmodeSequence">
int <code class="sig-name descname">PyArray_ConvertClipmodeSequence</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> object</em>, <a class="reference internal" href="#c.NPY_CLIPMODE" title="NPY_CLIPMODE">NPY_CLIPMODE</a>*<em> modes</em>, int<em> n</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_ConvertClipmodeSequence" title="Permalink to this definition">¶</a></dt>
<dd><p>Converts either a sequence of clipmodes or a single clipmode into
a C array of <a class="reference internal" href="#c.NPY_CLIPMODE" title="NPY_CLIPMODE"><code class="xref c c-type docutils literal notranslate"><span class="pre">NPY_CLIPMODE</span></code></a> values. The number of clipmodes <em>n</em>
must be known before calling this function. This function is provided
to help functions allow a different clipmode for each dimension.</p>
</dd></dl>

</div>
<div class="section" id="other-conversions">
<h3>Other conversions<a class="headerlink" href="#other-conversions" title="Permalink to this headline">¶</a></h3>
<dl class="function">
<dt id="c.PyArray_PyIntAsInt">
int <code class="sig-name descname">PyArray_PyIntAsInt</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> op</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_PyIntAsInt" title="Permalink to this definition">¶</a></dt>
<dd><p>Convert all kinds of Python objects (including arrays and array
scalars) to a standard integer. On error, -1 is returned and an
exception set. You may find useful the macro:</p>
<div class="highlight-c notranslate"><div class="highlight"><pre><span></span><span class="cp">#define error_converting(x) (((x) == -1) &amp;&amp; PyErr_Occurred()</span>
</pre></div>
</div>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_PyIntAsIntp">
<a class="reference internal" href="dtype.html#c.npy_intp" title="npy_intp">npy_intp</a> <code class="sig-name descname">PyArray_PyIntAsIntp</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> op</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_PyIntAsIntp" title="Permalink to this definition">¶</a></dt>
<dd><p>Convert all kinds of Python objects (including arrays and array
scalars) to a (platform-pointer-sized) integer. On error, -1 is
returned and an exception set.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_IntpFromSequence">
int <code class="sig-name descname">PyArray_IntpFromSequence</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> seq</em>, <a class="reference internal" href="dtype.html#c.npy_intp" title="npy_intp">npy_intp</a>*<em> vals</em>, int<em> maxvals</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_IntpFromSequence" title="Permalink to this definition">¶</a></dt>
<dd><p>Convert any Python sequence (or single Python number) passed in as
<em>seq</em> to (up to) <em>maxvals</em> pointer-sized integers and place them
in the <em>vals</em> array. The sequence can be smaller then <em>maxvals</em> as
the number of converted objects is returned.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_TypestrConvert">
int <code class="sig-name descname">PyArray_TypestrConvert</code><span class="sig-paren">(</span>int<em> itemsize</em>, int<em> gentype</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_TypestrConvert" title="Permalink to this definition">¶</a></dt>
<dd><p>Convert typestring characters (with <em>itemsize</em>) to basic
enumerated data types. The typestring character corresponding to
signed and unsigned integers, floating point numbers, and
complex-floating point numbers are recognized and converted. Other
values of gentype are returned. This function can be used to
convert, for example, the string ‘f4’ to <a class="reference internal" href="dtype.html#c.NPY_FLOAT32" title="NPY_FLOAT32"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_FLOAT32</span></code></a>.</p>
</dd></dl>

</div>
</div>
<div class="section" id="miscellaneous">
<h2>Miscellaneous<a class="headerlink" href="#miscellaneous" title="Permalink to this headline">¶</a></h2>
<div class="section" id="importing-the-api">
<h3>Importing the API<a class="headerlink" href="#importing-the-api" title="Permalink to this headline">¶</a></h3>
<p>In order to make use of the C-API from another extension module, the
<a class="reference internal" href="#c.import_array" title="import_array"><code class="xref c c-func docutils literal notranslate"><span class="pre">import_array</span></code></a> function must be called. If the extension module is
self-contained in a single .c file, then that is all that needs to be
done. If, however, the extension module involves multiple files where
the C-API is needed then some additional steps must be taken.</p>
<dl class="function">
<dt id="c.import_array">
void <code class="sig-name descname">import_array</code><span class="sig-paren">(</span>void<span class="sig-paren">)</span><a class="headerlink" href="#c.import_array" title="Permalink to this definition">¶</a></dt>
<dd><p>This function must be called in the initialization section of a
module that will make use of the C-API. It imports the module
where the function-pointer table is stored and points the correct
variable to it.</p>
</dd></dl>

<dl class="macro">
<dt id="c.PY_ARRAY_UNIQUE_SYMBOL">
<code class="sig-name descname">PY_ARRAY_UNIQUE_SYMBOL</code><a class="headerlink" href="#c.PY_ARRAY_UNIQUE_SYMBOL" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="macro">
<dt id="c.NO_IMPORT_ARRAY">
<code class="sig-name descname">NO_IMPORT_ARRAY</code><a class="headerlink" href="#c.NO_IMPORT_ARRAY" title="Permalink to this definition">¶</a></dt>
<dd><p>Using these #defines you can use the C-API in multiple files for a
single extension module. In each file you must define
<a class="reference internal" href="#c.PY_ARRAY_UNIQUE_SYMBOL" title="PY_ARRAY_UNIQUE_SYMBOL"><code class="xref c c-macro docutils literal notranslate"><span class="pre">PY_ARRAY_UNIQUE_SYMBOL</span></code></a> to some name that will hold the
C-API (<em>e.g.</em> myextension_ARRAY_API). This must be done <strong>before</strong>
including the numpy/arrayobject.h file. In the module
initialization routine you call <a class="reference internal" href="#c.import_array" title="import_array"><code class="xref c c-func docutils literal notranslate"><span class="pre">import_array</span></code></a>. In addition,
in the files that do not have the module initialization
sub_routine define <a class="reference internal" href="#c.NO_IMPORT_ARRAY" title="NO_IMPORT_ARRAY"><code class="xref c c-macro docutils literal notranslate"><span class="pre">NO_IMPORT_ARRAY</span></code></a> prior to including
numpy/arrayobject.h.</p>
<p>Suppose I have two files coolmodule.c and coolhelper.c which need
to be compiled and linked into a single extension module. Suppose
coolmodule.c contains the required initcool module initialization
function (with the import_array() function called). Then,
coolmodule.c would have at the top:</p>
<div class="highlight-c notranslate"><div class="highlight"><pre><span></span><span class="cp">#define PY_ARRAY_UNIQUE_SYMBOL cool_ARRAY_API</span>
<span class="cp">#include</span> <span class="cpf">numpy/arrayobject.h</span><span class="cp"></span>
</pre></div>
</div>
<p>On the other hand, coolhelper.c would contain at the top:</p>
<div class="highlight-c notranslate"><div class="highlight"><pre><span></span><span class="cp">#define NO_IMPORT_ARRAY</span>
<span class="cp">#define PY_ARRAY_UNIQUE_SYMBOL cool_ARRAY_API</span>
<span class="cp">#include</span> <span class="cpf">numpy/arrayobject.h</span><span class="cp"></span>
</pre></div>
</div>
<p>You can also put the common two last lines into an extension-local
header file as long as you make sure that NO_IMPORT_ARRAY is
#defined before #including that file.</p>
<p>Internally, these #defines work as follows:</p>
<blockquote>
<div><ul class="simple">
<li><p>If neither is defined, the C-API is declared to be
<code class="xref c c-type docutils literal notranslate"><span class="pre">static</span> <span class="pre">void**</span></code>, so it is only visible within the
compilation unit that #includes numpy/arrayobject.h.</p></li>
<li><p>If <a class="reference internal" href="#c.PY_ARRAY_UNIQUE_SYMBOL" title="PY_ARRAY_UNIQUE_SYMBOL"><code class="xref c c-macro docutils literal notranslate"><span class="pre">PY_ARRAY_UNIQUE_SYMBOL</span></code></a> is #defined, but
<a class="reference internal" href="#c.NO_IMPORT_ARRAY" title="NO_IMPORT_ARRAY"><code class="xref c c-macro docutils literal notranslate"><span class="pre">NO_IMPORT_ARRAY</span></code></a> is not, the C-API is declared to
be <code class="xref c c-type docutils literal notranslate"><span class="pre">void**</span></code>, so that it will also be visible to other
compilation units.</p></li>
<li><p>If <a class="reference internal" href="#c.NO_IMPORT_ARRAY" title="NO_IMPORT_ARRAY"><code class="xref c c-macro docutils literal notranslate"><span class="pre">NO_IMPORT_ARRAY</span></code></a> is #defined, regardless of
whether <a class="reference internal" href="#c.PY_ARRAY_UNIQUE_SYMBOL" title="PY_ARRAY_UNIQUE_SYMBOL"><code class="xref c c-macro docutils literal notranslate"><span class="pre">PY_ARRAY_UNIQUE_SYMBOL</span></code></a> is, the C-API is
declared to be <code class="xref c c-type docutils literal notranslate"><span class="pre">extern</span> <span class="pre">void**</span></code>, so it is expected to
be defined in another compilation unit.</p></li>
<li><p>Whenever <a class="reference internal" href="#c.PY_ARRAY_UNIQUE_SYMBOL" title="PY_ARRAY_UNIQUE_SYMBOL"><code class="xref c c-macro docutils literal notranslate"><span class="pre">PY_ARRAY_UNIQUE_SYMBOL</span></code></a> is #defined, it
also changes the name of the variable holding the C-API, which
defaults to <code class="xref c c-data docutils literal notranslate"><span class="pre">PyArray_API</span></code>, to whatever the macro is
#defined to.</p></li>
</ul>
</div></blockquote>
</dd></dl>

</div>
<div class="section" id="checking-the-api-version">
<h3>Checking the API Version<a class="headerlink" href="#checking-the-api-version" title="Permalink to this headline">¶</a></h3>
<p>Because python extensions are not used in the same way as usual libraries on
most platforms, some errors cannot be automatically detected at build time or
even runtime. For example, if you build an extension using a function available
only for numpy &gt;= 1.3.0, and you import the extension later with numpy 1.2, you
will not get an import error (but almost certainly a segmentation fault when
calling the function). That’s why several functions are provided to check for
numpy versions. The macros <a class="reference internal" href="#c.NPY_VERSION" title="NPY_VERSION"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_VERSION</span></code></a>  and
<code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_FEATURE_VERSION</span></code> corresponds to the numpy version used to build the
extension, whereas the versions returned by the functions
PyArray_GetNDArrayCVersion and PyArray_GetNDArrayCFeatureVersion corresponds to
the runtime numpy’s version.</p>
<p>The rules for ABI and API compatibilities can be summarized as follows:</p>
<blockquote>
<div><ul class="simple">
<li><p>Whenever <a class="reference internal" href="#c.NPY_VERSION" title="NPY_VERSION"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_VERSION</span></code></a> != PyArray_GetNDArrayCVersion, the
extension has to be recompiled (ABI incompatibility).</p></li>
<li><p><a class="reference internal" href="#c.NPY_VERSION" title="NPY_VERSION"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_VERSION</span></code></a> == PyArray_GetNDArrayCVersion and
<code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_FEATURE_VERSION</span></code> &lt;= PyArray_GetNDArrayCFeatureVersion means
backward compatible changes.</p></li>
</ul>
</div></blockquote>
<p>ABI incompatibility is automatically detected in every numpy’s version. API
incompatibility detection was added in numpy 1.4.0. If you want to supported
many different numpy versions with one extension binary, you have to build your
extension with the lowest NPY_FEATURE_VERSION as possible.</p>
<dl class="function">
<dt id="c.PyArray_GetNDArrayCVersion">
unsigned int <code class="sig-name descname">PyArray_GetNDArrayCVersion</code><span class="sig-paren">(</span>void<span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_GetNDArrayCVersion" title="Permalink to this definition">¶</a></dt>
<dd><p>This just returns the value <a class="reference internal" href="#c.NPY_VERSION" title="NPY_VERSION"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_VERSION</span></code></a>. <a class="reference internal" href="#c.NPY_VERSION" title="NPY_VERSION"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_VERSION</span></code></a>
changes whenever a backward incompatible change at the ABI level. Because
it is in the C-API, however, comparing the output of this function from the
value defined in the current header gives a way to test if the C-API has
changed thus requiring a re-compilation of extension modules that use the
C-API. This is automatically checked in the function <a class="reference internal" href="#c.import_array" title="import_array"><code class="xref c c-func docutils literal notranslate"><span class="pre">import_array</span></code></a>.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_GetNDArrayCFeatureVersion">
unsigned int <code class="sig-name descname">PyArray_GetNDArrayCFeatureVersion</code><span class="sig-paren">(</span>void<span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_GetNDArrayCFeatureVersion" title="Permalink to this definition">¶</a></dt>
<dd><div class="versionadded">
<p><span class="versionmodified added">New in version 1.4.0.</span></p>
</div>
<p>This just returns the value <code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_FEATURE_VERSION</span></code>.
<code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_FEATURE_VERSION</span></code> changes whenever the API changes (e.g. a
function is added). A changed value does not always require a recompile.</p>
</dd></dl>

</div>
<div class="section" id="internal-flexibility">
<h3>Internal Flexibility<a class="headerlink" href="#internal-flexibility" title="Permalink to this headline">¶</a></h3>
<dl class="function">
<dt id="c.PyArray_SetNumericOps">
int <code class="sig-name descname">PyArray_SetNumericOps</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> dict</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_SetNumericOps" title="Permalink to this definition">¶</a></dt>
<dd><p>NumPy stores an internal table of Python callable objects that are
used to implement arithmetic operations for arrays as well as
certain array calculation methods. This function allows the user
to replace any or all of these Python objects with their own
versions. The keys of the dictionary, <em>dict</em>, are the named
functions to replace and the paired value is the Python callable
object to use. Care should be taken that the function used to
replace an internal array operation does not itself call back to
that internal array operation (unless you have designed the
function to handle that), or an unchecked infinite recursion can
result (possibly causing program crash). The key names that
represent operations that can be replaced are:</p>
<blockquote>
<div><p><strong>add</strong>, <strong>subtract</strong>, <strong>multiply</strong>, <strong>divide</strong>,
<strong>remainder</strong>, <strong>power</strong>, <strong>square</strong>, <strong>reciprocal</strong>,
<strong>ones_like</strong>, <strong>sqrt</strong>, <strong>negative</strong>, <strong>positive</strong>,
<strong>absolute</strong>, <strong>invert</strong>, <strong>left_shift</strong>, <strong>right_shift</strong>,
<strong>bitwise_and</strong>, <strong>bitwise_xor</strong>, <strong>bitwise_or</strong>,
<strong>less</strong>, <strong>less_equal</strong>, <strong>equal</strong>, <strong>not_equal</strong>,
<strong>greater</strong>, <strong>greater_equal</strong>, <strong>floor_divide</strong>,
<strong>true_divide</strong>, <strong>logical_or</strong>, <strong>logical_and</strong>,
<strong>floor</strong>, <strong>ceil</strong>, <strong>maximum</strong>, <strong>minimum</strong>, <strong>rint</strong>.</p>
</div></blockquote>
<p>These functions are included here because they are used at least once
in the array object’s methods. The function returns -1 (without
setting a Python Error) if one of the objects being assigned is not
callable.</p>
<div class="deprecated">
<p><span class="versionmodified deprecated">Deprecated since version 1.16.</span></p>
</div>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_GetNumericOps">
<a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>* <code class="sig-name descname">PyArray_GetNumericOps</code><span class="sig-paren">(</span>void<span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_GetNumericOps" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a Python dictionary containing the callable Python objects
stored in the internal arithmetic operation table. The keys of
this dictionary are given in the explanation for <a class="reference internal" href="#c.PyArray_SetNumericOps" title="PyArray_SetNumericOps"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_SetNumericOps</span></code></a>.</p>
<div class="deprecated">
<p><span class="versionmodified deprecated">Deprecated since version 1.16.</span></p>
</div>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_SetStringFunction">
void <code class="sig-name descname">PyArray_SetStringFunction</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> op</em>, int<em> repr</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_SetStringFunction" title="Permalink to this definition">¶</a></dt>
<dd><p>This function allows you to alter the tp_str and tp_repr methods
of the array object to any Python function. Thus you can alter
what happens for all arrays when str(arr) or repr(arr) is called
from Python. The function to be called is passed in as <em>op</em>. If
<em>repr</em> is non-zero, then this function will be called in response
to repr(arr), otherwise the function will be called in response to
str(arr). No check on whether or not <em>op</em> is callable is
performed. The callable passed in to <em>op</em> should expect an array
argument and should return a string to be printed.</p>
</dd></dl>

</div>
<div class="section" id="memory-management">
<h3>Memory management<a class="headerlink" href="#memory-management" title="Permalink to this headline">¶</a></h3>
<dl class="function">
<dt id="c.PyDataMem_NEW">
char* <code class="sig-name descname">PyDataMem_NEW</code><span class="sig-paren">(</span>size_t<em> nbytes</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyDataMem_NEW" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="function">
<dt id="c.PyDataMem_FREE">
<code class="sig-name descname">PyDataMem_FREE</code><span class="sig-paren">(</span>char*<em> ptr</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyDataMem_FREE" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="function">
<dt id="c.PyDataMem_RENEW">
char* <code class="sig-name descname">PyDataMem_RENEW</code><span class="sig-paren">(</span>void *<em> ptr</em>, size_t<em> newbytes</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyDataMem_RENEW" title="Permalink to this definition">¶</a></dt>
<dd><p>Macros to allocate, free, and reallocate memory. These macros are used
internally to create arrays.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyDimMem_NEW">
<a class="reference internal" href="dtype.html#c.npy_intp" title="npy_intp">npy_intp</a>*  <code class="sig-name descname">PyDimMem_NEW</code><span class="sig-paren">(</span>int<em> nd</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyDimMem_NEW" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="function">
<dt id="c.PyDimMem_FREE">
<code class="sig-name descname">PyDimMem_FREE</code><span class="sig-paren">(</span>char*<em> ptr</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyDimMem_FREE" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="function">
<dt id="c.PyDimMem_RENEW">
<a class="reference internal" href="dtype.html#c.npy_intp" title="npy_intp">npy_intp</a>* <code class="sig-name descname">PyDimMem_RENEW</code><span class="sig-paren">(</span>void*<em> ptr</em>, size_t<em> newnd</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyDimMem_RENEW" title="Permalink to this definition">¶</a></dt>
<dd><p>Macros to allocate, free, and reallocate dimension and strides memory.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_malloc">
void* <code class="sig-name descname">PyArray_malloc</code><span class="sig-paren">(</span>size_t<em> nbytes</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_malloc" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="function">
<dt id="c.PyArray_free">
<code class="sig-name descname">PyArray_free</code><span class="sig-paren">(</span>void*<em> ptr</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_free" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="function">
<dt id="c.PyArray_realloc">
void* <code class="sig-name descname">PyArray_realloc</code><span class="sig-paren">(</span><a class="reference internal" href="dtype.html#c.npy_intp" title="npy_intp">npy_intp</a>*<em> ptr</em>, size_t<em> nbytes</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_realloc" title="Permalink to this definition">¶</a></dt>
<dd><p>These macros use different memory allocators, depending on the
constant <code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_USE_PYMEM</span></code>. The system malloc is used when
<code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_USE_PYMEM</span></code> is 0, if <code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_USE_PYMEM</span></code> is 1, then
the Python memory allocator is used.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_ResolveWritebackIfCopy">
int <code class="sig-name descname">PyArray_ResolveWritebackIfCopy</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a>*<em> obj</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_ResolveWritebackIfCopy" title="Permalink to this definition">¶</a></dt>
<dd><p>If <code class="docutils literal notranslate"><span class="pre">obj.flags</span></code> has <a class="reference internal" href="#c.NPY_ARRAY_WRITEBACKIFCOPY" title="NPY_ARRAY_WRITEBACKIFCOPY"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_WRITEBACKIFCOPY</span></code></a> or (deprecated)
<a class="reference internal" href="#c.NPY_ARRAY_UPDATEIFCOPY" title="NPY_ARRAY_UPDATEIFCOPY"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_UPDATEIFCOPY</span></code></a>, this function clears the flags, <em class="xref py py-obj">DECREF</em> s
<em class="xref py py-obj">obj-&gt;base</em> and makes it writeable, and sets <code class="docutils literal notranslate"><span class="pre">obj-&gt;base</span></code> to NULL. It then
copies <code class="docutils literal notranslate"><span class="pre">obj-&gt;data</span></code> to <em class="xref py py-obj">obj-&gt;base-&gt;data</em>, and returns the error state of
the copy operation. This is the opposite of
<a class="reference internal" href="#c.PyArray_SetWritebackIfCopyBase" title="PyArray_SetWritebackIfCopyBase"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_SetWritebackIfCopyBase</span></code></a>. Usually this is called once
you are finished with <code class="docutils literal notranslate"><span class="pre">obj</span></code>, just before <code class="docutils literal notranslate"><span class="pre">Py_DECREF(obj)</span></code>. It may be called
multiple times, or with <code class="docutils literal notranslate"><span class="pre">NULL</span></code> input. See also
<a class="reference internal" href="#c.PyArray_DiscardWritebackIfCopy" title="PyArray_DiscardWritebackIfCopy"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_DiscardWritebackIfCopy</span></code></a>.</p>
<p>Returns 0 if nothing was done, -1 on error, and 1 if action was taken.</p>
</dd></dl>

</div>
<div class="section" id="threading-support">
<h3>Threading support<a class="headerlink" href="#threading-support" title="Permalink to this headline">¶</a></h3>
<p>These macros are only meaningful if <code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ALLOW_THREADS</span></code>
evaluates True during compilation of the extension module. Otherwise,
these macros are equivalent to whitespace. Python uses a single Global
Interpreter Lock (GIL) for each Python process so that only a single
thread may execute at a time (even on multi-cpu machines). When
calling out to a compiled function that may take time to compute (and
does not have side-effects for other threads like updated global
variables), the GIL should be released so that other Python threads
can run while the time-consuming calculations are performed. This can
be accomplished using two groups of macros. Typically, if one macro in
a group is used in a code block, all of them must be used in the same
code block. Currently, <code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ALLOW_THREADS</span></code> is defined to the
python-defined <code class="xref c c-data docutils literal notranslate"><span class="pre">WITH_THREADS</span></code> constant unless the environment
variable <code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_NOSMP</span></code> is set in which case
<code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ALLOW_THREADS</span></code> is defined to be 0.</p>
<div class="section" id="group-1">
<h4>Group 1<a class="headerlink" href="#group-1" title="Permalink to this headline">¶</a></h4>
<blockquote>
<div><p>This group is used to call code that may take some time but does not
use any Python C-API calls. Thus, the GIL should be released during
its calculation.</p>
<dl class="macro">
<dt id="c.NPY_BEGIN_ALLOW_THREADS">
<code class="sig-name descname">NPY_BEGIN_ALLOW_THREADS</code><a class="headerlink" href="#c.NPY_BEGIN_ALLOW_THREADS" title="Permalink to this definition">¶</a></dt>
<dd><p>Equivalent to <a class="reference external" href="https://docs.python.org/dev/c-api/init.html#c.Py_BEGIN_ALLOW_THREADS" title="(in Python v3.9)"><code class="xref c c-macro docutils literal notranslate"><span class="pre">Py_BEGIN_ALLOW_THREADS</span></code></a> except it uses
<code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ALLOW_THREADS</span></code> to determine if the macro if
replaced with white-space or not.</p>
</dd></dl>

<dl class="macro">
<dt id="c.NPY_END_ALLOW_THREADS">
<code class="sig-name descname">NPY_END_ALLOW_THREADS</code><a class="headerlink" href="#c.NPY_END_ALLOW_THREADS" title="Permalink to this definition">¶</a></dt>
<dd><p>Equivalent to <a class="reference external" href="https://docs.python.org/dev/c-api/init.html#c.Py_END_ALLOW_THREADS" title="(in Python v3.9)"><code class="xref c c-macro docutils literal notranslate"><span class="pre">Py_END_ALLOW_THREADS</span></code></a> except it uses
<code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ALLOW_THREADS</span></code> to determine if the macro if
replaced with white-space or not.</p>
</dd></dl>

<dl class="macro">
<dt id="c.NPY_BEGIN_THREADS_DEF">
<code class="sig-name descname">NPY_BEGIN_THREADS_DEF</code><a class="headerlink" href="#c.NPY_BEGIN_THREADS_DEF" title="Permalink to this definition">¶</a></dt>
<dd><p>Place in the variable declaration area. This macro sets up the
variable needed for storing the Python state.</p>
</dd></dl>

<dl class="macro">
<dt id="c.NPY_BEGIN_THREADS">
<code class="sig-name descname">NPY_BEGIN_THREADS</code><a class="headerlink" href="#c.NPY_BEGIN_THREADS" title="Permalink to this definition">¶</a></dt>
<dd><p>Place right before code that does not need the Python
interpreter (no Python C-API calls). This macro saves the
Python state and releases the GIL.</p>
</dd></dl>

<dl class="macro">
<dt id="c.NPY_END_THREADS">
<code class="sig-name descname">NPY_END_THREADS</code><a class="headerlink" href="#c.NPY_END_THREADS" title="Permalink to this definition">¶</a></dt>
<dd><p>Place right after code that does not need the Python
interpreter. This macro acquires the GIL and restores the
Python state from the saved variable.</p>
</dd></dl>

<dl class="function">
<dt id="c.NPY_BEGIN_THREADS_DESCR">
<code class="sig-name descname">NPY_BEGIN_THREADS_DESCR</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a><em> *dtype</em><span class="sig-paren">)</span><a class="headerlink" href="#c.NPY_BEGIN_THREADS_DESCR" title="Permalink to this definition">¶</a></dt>
<dd><p>Useful to release the GIL only if <em>dtype</em> does not contain
arbitrary Python objects which may need the Python interpreter
during execution of the loop.</p>
</dd></dl>

<dl class="function">
<dt id="c.NPY_END_THREADS_DESCR">
<code class="sig-name descname">NPY_END_THREADS_DESCR</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArray_Descr" title="PyArray_Descr">PyArray_Descr</a><em> *dtype</em><span class="sig-paren">)</span><a class="headerlink" href="#c.NPY_END_THREADS_DESCR" title="Permalink to this definition">¶</a></dt>
<dd><p>Useful to regain the GIL in situations where it was released
using the BEGIN form of this macro.</p>
</dd></dl>

<dl class="function">
<dt id="c.NPY_BEGIN_THREADS_THRESHOLDED">
<code class="sig-name descname">NPY_BEGIN_THREADS_THRESHOLDED</code><span class="sig-paren">(</span>int<em> loop_size</em><span class="sig-paren">)</span><a class="headerlink" href="#c.NPY_BEGIN_THREADS_THRESHOLDED" title="Permalink to this definition">¶</a></dt>
<dd><p>Useful to release the GIL only if <em>loop_size</em> exceeds a
minimum threshold, currently set to 500. Should be matched
with a <a class="reference internal" href="#c.NPY_END_THREADS" title="NPY_END_THREADS"><code class="xref c c-macro docutils literal notranslate"><span class="pre">NPY_END_THREADS</span></code></a> to regain the GIL.</p>
</dd></dl>

</div></blockquote>
</div>
<div class="section" id="group-2">
<h4>Group 2<a class="headerlink" href="#group-2" title="Permalink to this headline">¶</a></h4>
<blockquote>
<div><p>This group is used to re-acquire the Python GIL after it has been
released. For example, suppose the GIL has been released (using the
previous calls), and then some path in the code (perhaps in a
different subroutine) requires use of the Python C-API, then these
macros are useful to acquire the GIL. These macros accomplish
essentially a reverse of the previous three (acquire the LOCK saving
what state it had) and then re-release it with the saved state.</p>
<dl class="macro">
<dt id="c.NPY_ALLOW_C_API_DEF">
<code class="sig-name descname">NPY_ALLOW_C_API_DEF</code><a class="headerlink" href="#c.NPY_ALLOW_C_API_DEF" title="Permalink to this definition">¶</a></dt>
<dd><p>Place in the variable declaration area to set up the necessary
variable.</p>
</dd></dl>

<dl class="macro">
<dt id="c.NPY_ALLOW_C_API">
<code class="sig-name descname">NPY_ALLOW_C_API</code><a class="headerlink" href="#c.NPY_ALLOW_C_API" title="Permalink to this definition">¶</a></dt>
<dd><p>Place before code that needs to call the Python C-API (when it is
known that the GIL has already been released).</p>
</dd></dl>

<dl class="macro">
<dt id="c.NPY_DISABLE_C_API">
<code class="sig-name descname">NPY_DISABLE_C_API</code><a class="headerlink" href="#c.NPY_DISABLE_C_API" title="Permalink to this definition">¶</a></dt>
<dd><p>Place after code that needs to call the Python C-API (to re-release
the GIL).</p>
</dd></dl>

</div></blockquote>
<div class="admonition tip">
<p class="admonition-title">Tip</p>
<p>Never use semicolons after the threading support macros.</p>
</div>
</div>
</div>
<div class="section" id="priority">
<h3>Priority<a class="headerlink" href="#priority" title="Permalink to this headline">¶</a></h3>
<dl class="var">
<dt id="c.NPY_PRIORITY">
<code class="sig-name descname">NPY_PRIORITY</code><a class="headerlink" href="#c.NPY_PRIORITY" title="Permalink to this definition">¶</a></dt>
<dd><p>Default priority for arrays.</p>
</dd></dl>

<dl class="var">
<dt id="c.NPY_SUBTYPE_PRIORITY">
<code class="sig-name descname">NPY_SUBTYPE_PRIORITY</code><a class="headerlink" href="#c.NPY_SUBTYPE_PRIORITY" title="Permalink to this definition">¶</a></dt>
<dd><p>Default subtype priority.</p>
</dd></dl>

<dl class="var">
<dt id="c.NPY_SCALAR_PRIORITY">
<code class="sig-name descname">NPY_SCALAR_PRIORITY</code><a class="headerlink" href="#c.NPY_SCALAR_PRIORITY" title="Permalink to this definition">¶</a></dt>
<dd><p>Default scalar priority (very small)</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_GetPriority">
double <code class="sig-name descname">PyArray_GetPriority</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> obj</em>, double<em> def</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_GetPriority" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the <a class="reference internal" href="../arrays.classes.html#numpy.class.__array_priority__" title="numpy.class.__array_priority__"><code class="xref py py-obj docutils literal notranslate"><span class="pre">__array_priority__</span></code></a> attribute (converted to a
double) of <em>obj</em> or <em>def</em> if no attribute of that name
exists. Fast returns that avoid the attribute lookup are provided
for objects of type <a class="reference internal" href="types-and-structures.html#c.PyArray_Type" title="PyArray_Type"><code class="xref c c-data docutils literal notranslate"><span class="pre">PyArray_Type</span></code></a>.</p>
</dd></dl>

</div>
<div class="section" id="default-buffers">
<h3>Default buffers<a class="headerlink" href="#default-buffers" title="Permalink to this headline">¶</a></h3>
<dl class="var">
<dt id="c.NPY_BUFSIZE">
<code class="sig-name descname">NPY_BUFSIZE</code><a class="headerlink" href="#c.NPY_BUFSIZE" title="Permalink to this definition">¶</a></dt>
<dd><p>Default size of the user-settable internal buffers.</p>
</dd></dl>

<dl class="var">
<dt id="c.NPY_MIN_BUFSIZE">
<code class="sig-name descname">NPY_MIN_BUFSIZE</code><a class="headerlink" href="#c.NPY_MIN_BUFSIZE" title="Permalink to this definition">¶</a></dt>
<dd><p>Smallest size of user-settable internal buffers.</p>
</dd></dl>

<dl class="var">
<dt id="c.NPY_MAX_BUFSIZE">
<code class="sig-name descname">NPY_MAX_BUFSIZE</code><a class="headerlink" href="#c.NPY_MAX_BUFSIZE" title="Permalink to this definition">¶</a></dt>
<dd><p>Largest size allowed for the user-settable buffers.</p>
</dd></dl>

</div>
<div class="section" id="other-constants">
<h3>Other constants<a class="headerlink" href="#other-constants" title="Permalink to this headline">¶</a></h3>
<dl class="var">
<dt id="c.NPY_NUM_FLOATTYPE">
<code class="sig-name descname">NPY_NUM_FLOATTYPE</code><a class="headerlink" href="#c.NPY_NUM_FLOATTYPE" title="Permalink to this definition">¶</a></dt>
<dd><p>The number of floating-point types</p>
</dd></dl>

<dl class="var">
<dt id="c.NPY_MAXDIMS">
<code class="sig-name descname">NPY_MAXDIMS</code><a class="headerlink" href="#c.NPY_MAXDIMS" title="Permalink to this definition">¶</a></dt>
<dd><p>The maximum number of dimensions allowed in arrays.</p>
</dd></dl>

<dl class="var">
<dt id="c.NPY_MAXARGS">
<code class="sig-name descname">NPY_MAXARGS</code><a class="headerlink" href="#c.NPY_MAXARGS" title="Permalink to this definition">¶</a></dt>
<dd><p>The maximum number of array arguments that can be used in functions.</p>
</dd></dl>

<dl class="var">
<dt id="c.NPY_VERSION">
<code class="sig-name descname">NPY_VERSION</code><a class="headerlink" href="#c.NPY_VERSION" title="Permalink to this definition">¶</a></dt>
<dd><p>The current version of the ndarray object (check to see if this
variable is defined to guarantee the numpy/arrayobject.h header is
being used).</p>
</dd></dl>

<dl class="var">
<dt id="c.NPY_FALSE">
<code class="sig-name descname">NPY_FALSE</code><a class="headerlink" href="#c.NPY_FALSE" title="Permalink to this definition">¶</a></dt>
<dd><p>Defined as 0 for use with Bool.</p>
</dd></dl>

<dl class="var">
<dt id="c.NPY_TRUE">
<code class="sig-name descname">NPY_TRUE</code><a class="headerlink" href="#c.NPY_TRUE" title="Permalink to this definition">¶</a></dt>
<dd><p>Defined as 1 for use with Bool.</p>
</dd></dl>

<dl class="var">
<dt id="c.NPY_FAIL">
<code class="sig-name descname">NPY_FAIL</code><a class="headerlink" href="#c.NPY_FAIL" title="Permalink to this definition">¶</a></dt>
<dd><p>The return value of failed converter functions which are called using
the “O&amp;” syntax in <a class="reference external" href="https://docs.python.org/dev/c-api/arg.html#c.PyArg_ParseTuple" title="(in Python v3.9)"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArg_ParseTuple</span></code></a>-like functions.</p>
</dd></dl>

<dl class="var">
<dt id="c.NPY_SUCCEED">
<code class="sig-name descname">NPY_SUCCEED</code><a class="headerlink" href="#c.NPY_SUCCEED" title="Permalink to this definition">¶</a></dt>
<dd><p>The return value of successful converter functions which are called
using the “O&amp;” syntax in <a class="reference external" href="https://docs.python.org/dev/c-api/arg.html#c.PyArg_ParseTuple" title="(in Python v3.9)"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArg_ParseTuple</span></code></a>-like functions.</p>
</dd></dl>

</div>
<div class="section" id="miscellaneous-macros">
<h3>Miscellaneous Macros<a class="headerlink" href="#miscellaneous-macros" title="Permalink to this headline">¶</a></h3>
<dl class="function">
<dt id="c.PyArray_SAMESHAPE">
<code class="sig-name descname">PyArray_SAMESHAPE</code><span class="sig-paren">(</span><a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a><em> *a1</em>, <a class="reference internal" href="types-and-structures.html#c.PyArrayObject" title="PyArrayObject">PyArrayObject</a><em> *a2</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_SAMESHAPE" title="Permalink to this definition">¶</a></dt>
<dd><p>Evaluates as True if arrays <em>a1</em> and <em>a2</em> have the same shape.</p>
</dd></dl>

<dl class="var">
<dt id="c.a">
<code class="sig-name descname">a</code><a class="headerlink" href="#c.a" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="var">
<dt id="c.b">
<code class="sig-name descname">b</code><a class="headerlink" href="#c.b" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="macro">
<dt id="c.PyArray_MAX">
<code class="sig-name descname">PyArray_MAX</code><span class="sig-paren">(</span><a class="reference internal" href="#c.a" title="a">a</a>, <a class="reference internal" href="#c.b" title="b">b</a><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_MAX" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the maximum of <em>a</em> and <em>b</em>. If (<em>a</em>) or (<em>b</em>) are
expressions they are evaluated twice.</p>
</dd></dl>

<dl class="macro">
<dt id="c.PyArray_MIN">
<code class="sig-name descname">PyArray_MIN</code><span class="sig-paren">(</span><a class="reference internal" href="#c.a" title="a">a</a>, <a class="reference internal" href="#c.b" title="b">b</a><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_MIN" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the minimum of <em>a</em> and <em>b</em>. If (<em>a</em>) or (<em>b</em>) are
expressions they are evaluated twice.</p>
</dd></dl>

<dl class="macro">
<dt id="c.PyArray_CLT">
<code class="sig-name descname">PyArray_CLT</code><span class="sig-paren">(</span><a class="reference internal" href="#c.a" title="a">a</a>, <a class="reference internal" href="#c.b" title="b">b</a><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_CLT" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="macro">
<dt id="c.PyArray_CGT">
<code class="sig-name descname">PyArray_CGT</code><span class="sig-paren">(</span><a class="reference internal" href="#c.a" title="a">a</a>, <a class="reference internal" href="#c.b" title="b">b</a><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_CGT" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="macro">
<dt id="c.PyArray_CLE">
<code class="sig-name descname">PyArray_CLE</code><span class="sig-paren">(</span><a class="reference internal" href="#c.a" title="a">a</a>, <a class="reference internal" href="#c.b" title="b">b</a><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_CLE" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="macro">
<dt id="c.PyArray_CGE">
<code class="sig-name descname">PyArray_CGE</code><span class="sig-paren">(</span><a class="reference internal" href="#c.a" title="a">a</a>, <a class="reference internal" href="#c.b" title="b">b</a><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_CGE" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="macro">
<dt id="c.PyArray_CEQ">
<code class="sig-name descname">PyArray_CEQ</code><span class="sig-paren">(</span><a class="reference internal" href="#c.a" title="a">a</a>, <a class="reference internal" href="#c.b" title="b">b</a><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_CEQ" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="macro">
<dt id="c.PyArray_CNE">
<code class="sig-name descname">PyArray_CNE</code><span class="sig-paren">(</span><a class="reference internal" href="#c.a" title="a">a</a>, <a class="reference internal" href="#c.b" title="b">b</a><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_CNE" title="Permalink to this definition">¶</a></dt>
<dd><p>Implements the complex comparisons between two complex numbers
(structures with a real and imag member) using NumPy’s definition
of the ordering which is lexicographic: comparing the real parts
first and then the complex parts if the real parts are equal.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_REFCOUNT">
<code class="sig-name descname">PyArray_REFCOUNT</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> op</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_REFCOUNT" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the reference count of any Python object.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_DiscardWritebackIfCopy">
<code class="sig-name descname">PyArray_DiscardWritebackIfCopy</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> obj</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_DiscardWritebackIfCopy" title="Permalink to this definition">¶</a></dt>
<dd><p>If <code class="docutils literal notranslate"><span class="pre">obj.flags</span></code> has <a class="reference internal" href="#c.NPY_ARRAY_WRITEBACKIFCOPY" title="NPY_ARRAY_WRITEBACKIFCOPY"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_WRITEBACKIFCOPY</span></code></a> or (deprecated)
<a class="reference internal" href="#c.NPY_ARRAY_UPDATEIFCOPY" title="NPY_ARRAY_UPDATEIFCOPY"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_UPDATEIFCOPY</span></code></a>, this function clears the flags, <em class="xref py py-obj">DECREF</em> s
<em class="xref py py-obj">obj-&gt;base</em> and makes it writeable, and sets <code class="docutils literal notranslate"><span class="pre">obj-&gt;base</span></code> to NULL. In
contrast to <a class="reference internal" href="#c.PyArray_DiscardWritebackIfCopy" title="PyArray_DiscardWritebackIfCopy"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_DiscardWritebackIfCopy</span></code></a> it makes no attempt
to copy the data from <em class="xref py py-obj">obj-&gt;base</em> This undoes
<a class="reference internal" href="#c.PyArray_SetWritebackIfCopyBase" title="PyArray_SetWritebackIfCopyBase"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_SetWritebackIfCopyBase</span></code></a>. Usually this is called after an
error when you are finished with <code class="docutils literal notranslate"><span class="pre">obj</span></code>, just before <code class="docutils literal notranslate"><span class="pre">Py_DECREF(obj)</span></code>.
It may be called multiple times, or with <code class="docutils literal notranslate"><span class="pre">NULL</span></code> input.</p>
</dd></dl>

<dl class="function">
<dt id="c.PyArray_XDECREF_ERR">
<code class="sig-name descname">PyArray_XDECREF_ERR</code><span class="sig-paren">(</span><a class="reference external" href="https://docs.python.org/dev/c-api/structures.html#c.PyObject" title="(in Python v3.9)">PyObject</a>*<em> obj</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PyArray_XDECREF_ERR" title="Permalink to this definition">¶</a></dt>
<dd><p>Deprecated in 1.14, use <a class="reference internal" href="#c.PyArray_DiscardWritebackIfCopy" title="PyArray_DiscardWritebackIfCopy"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArray_DiscardWritebackIfCopy</span></code></a>
followed by <code class="docutils literal notranslate"><span class="pre">Py_XDECREF</span></code></p>
<p>DECREF’s an array object which may have the (deprecated)
<a class="reference internal" href="#c.NPY_ARRAY_UPDATEIFCOPY" title="NPY_ARRAY_UPDATEIFCOPY"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_UPDATEIFCOPY</span></code></a> or <a class="reference internal" href="#c.NPY_ARRAY_WRITEBACKIFCOPY" title="NPY_ARRAY_WRITEBACKIFCOPY"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_WRITEBACKIFCOPY</span></code></a>
flag set without causing the contents to be copied back into the
original array. Resets the <a class="reference internal" href="#c.NPY_ARRAY_WRITEABLE" title="NPY_ARRAY_WRITEABLE"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_ARRAY_WRITEABLE</span></code></a> flag on the base
object. This is useful for recovering from an error condition when
writeback semantics are used, but will lead to wrong results.</p>
</dd></dl>

</div>
<div class="section" id="enumerated-types">
<h3>Enumerated Types<a class="headerlink" href="#enumerated-types" title="Permalink to this headline">¶</a></h3>
<dl class="type">
<dt id="c.NPY_SORTKIND">
<code class="sig-name descname">NPY_SORTKIND</code><a class="headerlink" href="#c.NPY_SORTKIND" title="Permalink to this definition">¶</a></dt>
<dd><p>A special variable-type which can take on different values to indicate
the sorting algorithm being used.</p>
<dl class="var">
<dt id="c.NPY_QUICKSORT">
<code class="sig-name descname">NPY_QUICKSORT</code><a class="headerlink" href="#c.NPY_QUICKSORT" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="var">
<dt id="c.NPY_HEAPSORT">
<code class="sig-name descname">NPY_HEAPSORT</code><a class="headerlink" href="#c.NPY_HEAPSORT" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="var">
<dt id="c.NPY_MERGESORT">
<code class="sig-name descname">NPY_MERGESORT</code><a class="headerlink" href="#c.NPY_MERGESORT" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="var">
<dt id="c.NPY_STABLESORT">
<code class="sig-name descname">NPY_STABLESORT</code><a class="headerlink" href="#c.NPY_STABLESORT" title="Permalink to this definition">¶</a></dt>
<dd><p>Used as an alias of <a class="reference internal" href="#c.NPY_MERGESORT" title="NPY_MERGESORT"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_MERGESORT</span></code></a> and vica versa.</p>
</dd></dl>

<dl class="var">
<dt id="c.NPY_NSORTS">
<code class="sig-name descname">NPY_NSORTS</code><a class="headerlink" href="#c.NPY_NSORTS" title="Permalink to this definition">¶</a></dt>
<dd><p>Defined to be the number of sorts. It is fixed at three by the need for
backwards compatibility, and consequently <a class="reference internal" href="#c.NPY_MERGESORT" title="NPY_MERGESORT"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_MERGESORT</span></code></a> and
<a class="reference internal" href="#c.NPY_STABLESORT" title="NPY_STABLESORT"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_STABLESORT</span></code></a> are aliased to each other and may refer to one
of several stable sorting algorithms depending on the data type.</p>
</dd></dl>

</dd></dl>

<dl class="type">
<dt id="c.NPY_SCALARKIND">
<code class="sig-name descname">NPY_SCALARKIND</code><a class="headerlink" href="#c.NPY_SCALARKIND" title="Permalink to this definition">¶</a></dt>
<dd><p>A special variable type indicating the number of “kinds” of
scalars distinguished in determining scalar-coercion rules. This
variable can take on the values:</p>
<dl class="var">
<dt id="c.NPY_NOSCALAR">
<code class="sig-name descname">NPY_NOSCALAR</code><a class="headerlink" href="#c.NPY_NOSCALAR" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="var">
<dt id="c.NPY_BOOL_SCALAR">
<code class="sig-name descname">NPY_BOOL_SCALAR</code><a class="headerlink" href="#c.NPY_BOOL_SCALAR" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="var">
<dt id="c.NPY_INTPOS_SCALAR">
<code class="sig-name descname">NPY_INTPOS_SCALAR</code><a class="headerlink" href="#c.NPY_INTPOS_SCALAR" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="var">
<dt id="c.NPY_INTNEG_SCALAR">
<code class="sig-name descname">NPY_INTNEG_SCALAR</code><a class="headerlink" href="#c.NPY_INTNEG_SCALAR" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="var">
<dt id="c.NPY_FLOAT_SCALAR">
<code class="sig-name descname">NPY_FLOAT_SCALAR</code><a class="headerlink" href="#c.NPY_FLOAT_SCALAR" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="var">
<dt id="c.NPY_COMPLEX_SCALAR">
<code class="sig-name descname">NPY_COMPLEX_SCALAR</code><a class="headerlink" href="#c.NPY_COMPLEX_SCALAR" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="var">
<dt id="c.NPY_OBJECT_SCALAR">
<code class="sig-name descname">NPY_OBJECT_SCALAR</code><a class="headerlink" href="#c.NPY_OBJECT_SCALAR" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="var">
<dt id="c.NPY_NSCALARKINDS">
<code class="sig-name descname">NPY_NSCALARKINDS</code><a class="headerlink" href="#c.NPY_NSCALARKINDS" title="Permalink to this definition">¶</a></dt>
<dd><p>Defined to be the number of scalar kinds
(not including <a class="reference internal" href="#c.NPY_NOSCALAR" title="NPY_NOSCALAR"><code class="xref c c-data docutils literal notranslate"><span class="pre">NPY_NOSCALAR</span></code></a>).</p>
</dd></dl>

</dd></dl>

<dl class="type">
<dt id="c.NPY_ORDER">
<code class="sig-name descname">NPY_ORDER</code><a class="headerlink" href="#c.NPY_ORDER" title="Permalink to this definition">¶</a></dt>
<dd><p>An enumeration type indicating the element order that an array should be
interpreted in. When a brand new array is created, generally
only <strong>NPY_CORDER</strong> and <strong>NPY_FORTRANORDER</strong> are used, whereas
when one or more inputs are provided, the order can be based on them.</p>
<dl class="var">
<dt id="c.NPY_ANYORDER">
<code class="sig-name descname">NPY_ANYORDER</code><a class="headerlink" href="#c.NPY_ANYORDER" title="Permalink to this definition">¶</a></dt>
<dd><p>Fortran order if all the inputs are Fortran, C otherwise.</p>
</dd></dl>

<dl class="var">
<dt id="c.NPY_CORDER">
<code class="sig-name descname">NPY_CORDER</code><a class="headerlink" href="#c.NPY_CORDER" title="Permalink to this definition">¶</a></dt>
<dd><p>C order.</p>
</dd></dl>

<dl class="var">
<dt id="c.NPY_FORTRANORDER">
<code class="sig-name descname">NPY_FORTRANORDER</code><a class="headerlink" href="#c.NPY_FORTRANORDER" title="Permalink to this definition">¶</a></dt>
<dd><p>Fortran order.</p>
</dd></dl>

<dl class="var">
<dt id="c.NPY_KEEPORDER">
<code class="sig-name descname">NPY_KEEPORDER</code><a class="headerlink" href="#c.NPY_KEEPORDER" title="Permalink to this definition">¶</a></dt>
<dd><p>An order as close to the order of the inputs as possible, even
if the input is in neither C nor Fortran order.</p>
</dd></dl>

</dd></dl>

<dl class="type">
<dt id="c.NPY_CLIPMODE">
<code class="sig-name descname">NPY_CLIPMODE</code><a class="headerlink" href="#c.NPY_CLIPMODE" title="Permalink to this definition">¶</a></dt>
<dd><p>A variable type indicating the kind of clipping that should be
applied in certain functions.</p>
<dl class="var">
<dt>
<code class="sig-name descname">NPY_RAISE</code></dt>
<dd><p>The default for most operations, raises an exception if an index
is out of bounds.</p>
</dd></dl>

<dl class="var">
<dt>
<code class="sig-name descname">NPY_CLIP</code></dt>
<dd><p>Clips an index to the valid range if it is out of bounds.</p>
</dd></dl>

<dl class="var">
<dt>
<code class="sig-name descname">NPY_WRAP</code></dt>
<dd><p>Wraps an index to the valid range if it is out of bounds.</p>
</dd></dl>

</dd></dl>

<dl class="type">
<dt id="c.NPY_CASTING">
<code class="sig-name descname">NPY_CASTING</code><a class="headerlink" href="#c.NPY_CASTING" title="Permalink to this definition">¶</a></dt>
<dd><div class="versionadded">
<p><span class="versionmodified added">New in version 1.6.</span></p>
</div>
<p>An enumeration type indicating how permissive data conversions should
be. This is used by the iterator added in NumPy 1.6, and is intended
to be used more broadly in a future version.</p>
<dl class="var">
<dt id="c.NPY_NO_CASTING">
<code class="sig-name descname">NPY_NO_CASTING</code><a class="headerlink" href="#c.NPY_NO_CASTING" title="Permalink to this definition">¶</a></dt>
<dd><p>Only allow identical types.</p>
</dd></dl>

<dl class="var">
<dt id="c.NPY_EQUIV_CASTING">
<code class="sig-name descname">NPY_EQUIV_CASTING</code><a class="headerlink" href="#c.NPY_EQUIV_CASTING" title="Permalink to this definition">¶</a></dt>
<dd><p>Allow identical and casts involving byte swapping.</p>
</dd></dl>

<dl class="var">
<dt id="c.NPY_SAFE_CASTING">
<code class="sig-name descname">NPY_SAFE_CASTING</code><a class="headerlink" href="#c.NPY_SAFE_CASTING" title="Permalink to this definition">¶</a></dt>
<dd><p>Only allow casts which will not cause values to be rounded,
truncated, or otherwise changed.</p>
</dd></dl>

<dl class="var">
<dt id="c.NPY_SAME_KIND_CASTING">
<code class="sig-name descname">NPY_SAME_KIND_CASTING</code><a class="headerlink" href="#c.NPY_SAME_KIND_CASTING" title="Permalink to this definition">¶</a></dt>
<dd><p>Allow any safe casts, and casts between types of the same kind.
For example, float64 -&gt; float32 is permitted with this rule.</p>
</dd></dl>

<dl class="var">
<dt id="c.NPY_UNSAFE_CASTING">
<code class="sig-name descname">NPY_UNSAFE_CASTING</code><a class="headerlink" href="#c.NPY_UNSAFE_CASTING" title="Permalink to this definition">¶</a></dt>
<dd><p>Allow any cast, no matter what kind of data loss may occur.</p>
</dd></dl>

</dd></dl>

<span class="target" id="index-1"></span></div>
</div>
</div>


          </div>
        </div>
          </div>
        </div>
      </div>
    </div>

    <div class="container container-navbar-bottom">
      <div class="spc-navbar">
        
      </div>
    </div>
    <div class="container">
    <div class="footer">
    <div class="row-fluid">
    <ul class="inline pull-left">
      <li>
        &copy; Copyright 2008-2019, The SciPy community.
      </li>
      <li>
      Last updated on Feb 20, 2020.
      </li>
      <li>
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 2.4.2.
      </li>
    </ul>
    </div>
    </div>
    </div>
  </body>
</html>